C14D:Colorful World
总时间限制:
-
1000ms
内存限制:
-
65536kB
描述
-
Recently little F buys 2n lights and aligns them in a circle at his beautiful garden. On the first day, when night falls, little F lights up the lights with 2n different colors, and his girlfriend is lost in the dreamy scene.
On the next 2n-1 days, little F turns the colors of lights counter-clockwise once every day in order to please his girlfriend with different scene. Let’s say on the first day little F lights up the i-th (starts from 1) light with color ci, then on the second day, the i-th light’s color becomes ci+1 and (2n)-th light’s color becomes c1. On the other side, every light has certain brightness, i.e., no matter what color the light is, its brightness will never change.
On the k-th (starts from 1) day his girlfriend can get hk happiness. On the (2n+1)-th day, the scene is as same as the one on the first day and h2n+1 is equal to h1. Little F stops the lights show and quickly realizes that his girlfriend has various preferences over different colors. For color cj, if her likeness is aj, then it will give (aj∙bi) happiness if the brightness of the i-th light, with color cj, is bi. Finally hk equals to the sum of happiness of all the lights on the k-th day.
Little F has already recorded bj for each color cj and hk on each day. He wants to calculate ai, thus he can find better ways to please his girlfriend in the future. It’s guaranteed that for the given input, there is only one solution to ai.
输入
-
The first line contains an integer T (1 ≤ T ≤ 20) -- the number of test cases.
For each test case:
The first line contains an integer n. 1 ≤ n ≤ 10.
The second line contains 2
n integers, indicate b
1, b
2, ... , b
2n. 0 ≤ b ≤ 5 000.
The third line contains 2
n integers, indicate h
1, h
2, ... , h
2n. 0 ≤ h ≤ 5 000.
输出
-
For each test case, you should output 2
n real integer a
1, a
2, ... , a
2n in order, separated by a single space in a single line. Each number should be rounded to 2 digits after the decimal point.
样例输入
-
1
1
8 10
4 9
样例输出
-
1.61 -0.89
C14D:Colorful World
-
总时间限制:
- 1000ms 内存限制:
- 65536kB
-
描述
-
Recently little F buys 2n lights and aligns them in a circle at his beautiful garden. On the first day, when night falls, little F lights up the lights with 2n different colors, and his girlfriend is lost in the dreamy scene.
On the next 2n-1 days, little F turns the colors of lights counter-clockwise once every day in order to please his girlfriend with different scene. Let’s say on the first day little F lights up the i-th (starts from 1) light with color ci, then on the second day, the i-th light’s color becomes ci+1 and (2n)-th light’s color becomes c1. On the other side, every light has certain brightness, i.e., no matter what color the light is, its brightness will never change.
On the k-th (starts from 1) day his girlfriend can get hk happiness. On the (2n+1)-th day, the scene is as same as the one on the first day and h2n+1 is equal to h1. Little F stops the lights show and quickly realizes that his girlfriend has various preferences over different colors. For color cj, if her likeness is aj, then it will give (aj∙bi) happiness if the brightness of the i-th light, with color cj, is bi. Finally hk equals to the sum of happiness of all the lights on the k-th day.
Little F has already recorded bj for each color cj and hk on each day. He wants to calculate ai, thus he can find better ways to please his girlfriend in the future. It’s guaranteed that for the given input, there is only one solution to ai.
输入
-
The first line contains an integer T (1 ≤ T ≤ 20) -- the number of test cases.
For each test case:
The first line contains an integer n. 1 ≤ n ≤ 10.
The second line contains 2 n integers, indicate b 1, b 2, ... , b 2n. 0 ≤ b ≤ 5 000.
The third line contains 2 n integers, indicate h 1, h 2, ... , h 2n. 0 ≤ h ≤ 5 000.
输出
- For each test case, you should output 2 n real integer a 1, a 2, ... , a 2n in order, separated by a single space in a single line. Each number should be rounded to 2 digits after the decimal point. 样例输入
-
1 1 8 10 4 9
样例输出
-
1.61 -0.89
#include<iostream>
#include<cstdio>
#include<cmath>
#define SIZE 1050
using namespace std;
const double pi=3.1415926535897932384626;
int n,p2n;
class complex
{
public:
double x,y;
complex(double xx=0,double yy=0):x(xx),y(yy){};
};
complex operator +(complex a,complex b)
{
return complex(a.x+b.x,a.y+b.y);
}
complex operator *(complex a,complex b)
{
return complex(a.x*b.x-a.y*b.y,a.y*b.x+a.x*b.y);
}
complex inv(complex a)
{
double r2=a.x*a.x+a.y*a.y;
return complex(a.x/r2,-a.y/r2);
}
complex w(int k)
{
double theta=2*pi*k/p2n;
return complex(cos(theta),sin(theta));
}
complex b[SIZE],h[SIZE],v[SIZE][SIZE],v2[SIZE][SIZE];
int main()
{
int T;
cin>>T;
while(T--)
{
cin>>n;
p2n=(1<<n);
for(int i=0;i<p2n;i++)
{
double bb;
cin>>bb;
b[i]=complex(bb,0);
}
for(int i=0;i<p2n;i++)
{
double hh;
cin>>hh;
h[i]=complex(hh,0);
}
for(int i=0;i<p2n;i++)
for(int j=0;j<p2n;j++)
{
v[i][j]=w(i*j);
v2[i][j]=w(-i*j);
}
/**comput v2b*/
complex v2b[SIZE],vh[SIZE],a[SIZE];
for(int i=0;i<p2n;i++)
{
v2b[i]=complex(0,0);
for(int j=0;j<p2n;j++)
v2b[i]=v2b[i]+v2[i][j]*b[j];
}
/**comput vh*/
for(int i=0;i<p2n;i++)
{
vh[i]=complex(0,0);
for(int j=0;j<p2n;j++)
vh[i]=vh[i]+v[i][j]*h[j];
}
/**comput v2b./vh */
for(int i=0;i<p2n;i++)
v2b[i]=vh[i]*inv(v2b[i]);
/**comput a*/
for(int i=0;i<p2n;i++)
{
a[i]=complex(0,0);
for(int j=0;j<p2n;j++)
a[i]=a[i]+v2[i][j]*v2b[j];
a[i]=a[i]*complex(double(1.0/p2n),0);
printf("%.2f ",a[i].x);
}
printf("\n");
}
}