BZOJ3527:[ZJOI]力

无题面神题

原题意:

求所有的Ei=Fi/qi。

 

题解:

qi被除掉了,则原式中的qj可以忽略。

用a[i]表示q[i],用b[j-i]来表示±1/((j-i)^2)(j>i时为正,j<i时为负)

则求E[j]就是多项式乘法了。

因为是FFT,所以b的下标要增加到0及以上

这题时限有30s,比某题友好多了。

 

代码:

 1 type
 2   xs=record
 3     x,y:double;
 4   end;
 5   arr=array[0..1000000]of xs;
 6 var
 7   e,t:arr;
 8   a:array[1..5]of arr;
 9   n,m,i:longint;
10 function jian(a,b:xs):xs;
11 begin
12   jian.x:=a.x-b.x;
13   jian.y:=a.y-b.y;
14 end;
15 function jia(a,b:xs):xs;
16 begin
17   jia.x:=a.x+b.x;
18   jia.y:=a.y+b.y;
19 end;
20 function cheng(a,b:xs):xs;
21 begin
22   cheng.x:=a.x*b.x-a.y*b.y;
23   cheng.y:=a.x*b.y+a.y*b.x;
24 end;
25 procedure fft(xx,s,nn,mm:longint);
26 var
27   i,j:longint;
28   w:xs;
29 begin
30   if nn=1 then
31   begin a[xx+2,s]:=a[xx,s]; exit; end;
32   for i:=0 to nn div 2-1 do
33   begin t[i]:=a[xx,i*2+s]; t[i+nn div 2]:=a[xx,i*2+1+s]; end;
34   for i:=0 to nn-1 do a[xx,s+i]:=t[i];
35   fft(xx,s,nn div 2,mm*2); fft(xx,s+nn div 2,nn div 2,mm*2);
36   for i:=0 to nn div 2-1 do
37   begin
38     j:=s+i;
39     w:=cheng(e[i*mm],a[xx+2,j+nn div 2]);
40     t[j]:=jia(a[xx+2,j],w);
41     t[j+nn div 2]:=jian(a[xx+2,j],w);
42   end;
43   for i:=s to s+nn-1 do a[xx+2,i]:=t[i];
44 end;
45 begin
46   read(m);
47   for i:=0 to m-1 do read(a[1,i].x);
48   for i:=1 to m-1 do a[2,i].x:=-1/(m-i)/(m-i);
49   for i:=m+1 to m*2-1 do a[2,i].x:=1/(i-m)/(i-m);
50   n:=1;
51   while n<m*2 do n:=n*2;
52   for i:=0 to n-1 do e[i].x:=cos(pi*2*i/n);
53   for i:=0 to n-1 do e[i].y:=sin(pi*2*i/n);
54   fft(1,0,n,1); fft(2,0,n,1);
55   for i:=0 to n-1 do a[3,i]:=cheng(a[3,i],a[4,i]);
56   for i:=0 to n-1 do e[i].y:=-e[i].y;
57   fft(3,0,n,1);
58   for i:=m to m*2-1 do writeln((a[5,i].x/n):0:3);
59 end.
View Code
posted @ 2017-01-06 20:13  GhoStreach  阅读(247)  评论(1编辑  收藏  举报