[关闭]
@11101001 2018-04-29T11:06:52.000000Z 字数 2182 阅读 721

bzoj3527: [Zjoi2014]力

fast_fast_tle


题目链接

bzoj3527: [Zjoi2014]力

题解

大意:



求E
化简F得

带入,化简式得到

,得到

对与卷积式,FFT即可
因为
对于


得到原式
那么
该式也化成了卷积式,FFT求解即可
那么
FFT求解
有点卡精度,处理初值g时要吧i*i转化为double,或者/i/i

代码

  1. #include<cmath>
  2. #include<cstdio>
  3. #include<algorithm>
  4. inline int read() {
  5. int x = 0,f = 1;
  6. char c = getchar();
  7. while(c < '0' || c > '9') {if (c == '-') f = -1;c = getchar();}
  8. while(c <= '9' && c >= '0') x = x * 10 + c - '0',c = getchar();
  9. return x * f;
  10. }
  11. const int maxn = 300007;
  12. const double pi = acos(-1.0);
  13. double a[maxn];
  14. struct Complex {
  15. double x,y;
  16. Complex (double x = 0,double y = 0) : x(x),y(y) {};
  17. }f[maxn],g[maxn],c[maxn];
  18. Complex operator + (Complex a,Complex b) {return Complex(a.x + b.x,a.y + b.y); };
  19. Complex operator - (Complex a,Complex b) {return Complex(a.x - b.x,a.y - b.y); };
  20. Complex operator * (Complex a,Complex b) {return Complex(a.x * b.x - a.y * b.y,a.x * b.y + a.y * b.x); }
  21. int n,m;
  22. int l,r[maxn];
  23. int limit = 1;
  24. void FFT(Complex * A,int type) {
  25. for(int i = 0;i < limit;++ i)
  26. if(i < r[i]) std::swap(A[i],A[r[i]]);
  27. for(int mid = 1;mid < limit;mid <<= 1) {
  28. Complex wn (cos(pi / mid) , type * sin(pi / mid));
  29. for(int R = mid << 1,j = 0;j < limit;j += R) {
  30. Complex w(1,0);
  31. for(int k = 0;k < mid;k ++,w = w * wn) {
  32. Complex x = A[j + k],y = w * A[j + mid + k];
  33. A[j + k] = x + y;
  34. A[j + mid + k] = x - y;
  35. }
  36. }
  37. }
  38. if(type == - 1) for(int i = 0;i < limit;++ i) A[i].x /= limit;
  39. }
  40. int main() {
  41. n = read();double x;
  42. //printf("%d\n",n);
  43. for(int i = 0;i < n; ++ i)
  44. scanf("%lf",&x),f[i].x = g[n - i - 1].x = x;
  45. for(int i = 1; i < n;++ i)
  46. c[i].x = 1.0 / (1.0* i * i);
  47. while(limit <= n + n) limit <<= 1,l ++;
  48. //printf("%d\n",limit);
  49. for(int i = 0;i < limit;++ i)
  50. r[i] = (r[i >> 1] >> 1) | ((i & 1) << (l - 1));//,printf("%d ",r[i]);;
  51. //puts("");puts("");
  52. FFT(f,1) ,FFT(g,1);FFT(c,1);
  53. for(int i = 0;i < limit;++ i) f[i] = f[i] * c[i],g[i] = g[i] * c[i];
  54. FFT(f,-1);FFT(g,-1);
  55. for(int i = 0;i < n;++ i) printf("%.3lf\n",f[i].x - g[n - i -1].x);
  56. return 0;
  57. }
添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注