poj3444

简单题

View Code
#include <iostream>
#include
<cstdio>
#include
<cstdlib>
#include
<cstring>
using namespace std;

#define maxn 300

int n;
int f[maxn], g[maxn];

void input()
{
for (int i = 0; i < n; i++)
scanf(
"%d", &f[i]);
}

void work(int a)
{
for (int i = 0; i < a; i++)
{
g[i
* 2] = (f[i] + f[i + a]) / 2;
g[i
* 2 + 1] = (f[i] - f[i + a]) / 2;
}
for (int i = 0; i < 2 * a; i++)
f[i]
= g[i];
}

int main()
{
//freopen("t.txt", "r", stdin);
while (scanf("%d", &n), n)
{
input();
for (int k = 1; k < n; k <<= 1)
work(k);
printf(
"%d", f[0]);
for (int i = 1; i < n; i++)
printf(
" %d", f[i]);
putchar(
'\n');
}
return 0;
}

你可能感兴趣的:(poj)