21531_WaveletCompression

2022-5-16 18:19| 发布者: Hocassian| 查看: 35| 评论: 0|原作者: 肇庆学院ACM合集

摘要:
C:\Users\Administrator\Downloads\2019-10-12-10-14-4-89505395721000-Problem List-采集的数据-后羿采集器.html

Pro.ID

21531

Title

Wavelet Compression

Title链接

http://10.20.2.8/oj/exercise/problem?problem_id=21531

AC

0

Submit

0

Ratio

-

时间&空间限制

  • Time Limit: 4000/2000 MS (Java/Others)     Memory Limit: 65536/65536 K (Java/Others)
  • 描述

    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

    a(1), ..., a(n)

    the i-th sum s(i) and difference d(i) 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:

    5, 2, 3, 2, 5, 7, 9, 6

    Then the sum and difference signals are:

    s(i) = 7, 5, 12, 15   d(i) = 3, 1, -2, 3

    Thus, the transformed signal is:

    7, 5, 12, 15, 3, 1, -2, 3

    The same process is applied recursively to the first half of the transformed signal, treating s(i) as the input signal, until the length of the input signal is 1. In the example above, the final transformed signal is:

    39, -15, 2, -3, 3, 1, -2, 3

    It is assumed that the length of the original input is a power of 2, and the input signal consists of integers between 0 and 255 (inclusive) only.

    输入

    The input consists of a number of cases. Each case is specified on a line, starting with an integer N (1 ≤ N ≤ 256) indicating the number of samples. The next N integers are the transformed samples. The end of input is indicated by a case in which N = 0.

    输出

    Description

    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

    a(1), ..., a(n)

    the i-th sum s(i) and difference d(i) 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:

    5, 2, 3, 2, 5, 7, 9, 6

    Then the sum and difference signals are:

    s(i) = 7, 5, 12, 15   d(i) = 3, 1, -2, 3

    Thus, the transformed signal is:

    7, 5, 12, 15, 3, 1, -2, 3

    The same process is applied recursively to the first half of the transformed signal, treating s(i) as the input signal, until the length of the input signal is 1. In the example above, the final transformed signal is:

    39, -15, 2, -3, 3, 1, -2, 3

    It is assumed that the length of the original input is a power of 2, and the input signal consists of integers between 0 and 255 (inclusive) only.

    Input

    The input consists of a number of cases. Each case is specified on a line, starting with an integer N (1 ≤ N ≤ 256) indicating the number of samples. The next N integers are the transformed samples. The end of input is indicated by a case in which N = 0.

    Output

    For each test case, output the original samples on a single line, separated by a single space.

    Sample Input

    8 39 -15 2 -3 3 1 -2 3
    4 10 -4 -1 -1
    0

    Sample Output

    5 2 3 2 5 7 9 6
    1 2 3 4

    Source

    样例输入

    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

    作者


    路过

    雷人

    握手

    鲜花

    鸡蛋

    最新评论

    返回顶部