单点时限: 5.0 sec
内存限制: 256 MB
The discrete wavelet transform is a popular tool for signal compression. In this problem, your job is to write a program to decompress a one-dimensional signal (a list of integers) that has been compressed by a simple wavelet transform.
To understand how this simple wavelet transform works, suppose that we have a list of an even number of integers. We compute the sum and difference of each pair of consecutive samples, resulting in two lists of sums and differences each having half the original length. Formally, if the original samples are
the -th sum and difference are computed as:
for i = 1,...,n/2: s(i) = a(2*i-1) + a(2*i) d(i) = a(2*i-1) - a(2*i)
This is then rearranged to give the transformed signal by first listing the sums and then the differences. For example, if the input signal is:
Then the sum and difference signals are:
Thus, the transformed signal is:
The same process is applied recursively to the first half of the transformed signal, treating as the input signal, until the length of the input signal is . In the example above, the final transformed signal is:
It is assumed that the length of the original input is a power of , and the input signal consists of integers between and (inclusive) only.
The input consists of a number of cases. Each case is specified on a line, starting with an integer () indicating the number of samples. The next integers are the transformed samples. The end of input is indicated by a case in which .
For each test case, output the original samples on a single line, separated by a single space.
8 39 -15 2 -3 3 1 -2 3 4 10 -4 -1 -1 0
5 2 3 2 5 7 9 6 1 2 3 4