分析:网上别家的代码都分析的很好,我只是给我自己贴个代码,我是kuangbin的搬运工

一点想法:其实FFT就是快速求卷积罢了,当小数据的时候我们完全可以用母函数来做,比如那种硬币问题

FFT只是用来解决数据规模较大时的办法,可以达到nlogn的效率,大体原理就是运用了n次单位复根的折半引理

具体可以看算法导论

高度仰慕kuangbin大神的模板,实在是不想自己写

对于这个题,我们10^k的系数看成多项式系数,然后求卷积,进位就好了

  1. #include <stdio.h>
  2. #include <iostream>
  3. #include <algorithm>
  4. #include <string.h>
  5. #include <vector>
  6. #include <math.h>
  7. #include <map>
  8. using namespace std;
  9. typedef long long LL;
  10. const int INF=0x3f3f3f3f;
  11. const int N=2e5+;
  12. const double pi = acos(-1.0);
  13. struct complex{
  14. double r,i;
  15. complex(double R=,double I=){
  16. r=R;i=I;
  17. }
  18. complex operator+(const complex &a)const{
  19. return complex(r+a.r,i+a.i);
  20. }
  21. complex operator-(const complex &a)const{
  22. return complex(r-a.r,i-a.i);
  23. }
  24. complex operator*(const complex &a)const{
  25. return complex(r*a.r-i*a.i,r*a.i+i*a.r);
  26. }
  27. };
  28. void change(complex x[],int len){
  29. int i,j,k;
  30. for(i=,j=len/;i<len-;++i){
  31. if(i<j)swap(x[i],x[j]);
  32. k=len/;
  33. while(j>=k){j-=k;k>>=;}
  34. if(j<k)j+=k;
  35. }
  36. }
  37. void fft(complex x[],int len,int on){
  38. change(x,len);
  39. for(int i=;i<=len;i<<=){
  40. complex wn(cos(-on**pi/i),sin(-on**pi/i));
  41. for(int j=;j<len;j+=i){
  42. complex w(,);
  43. for(int k=j;k<j+i/;++k){
  44. complex u = x[k];
  45. complex t = w*x[k+i/];
  46. x[k]=u+t;
  47. x[k+i/]=u-t;
  48. w=w*wn;
  49. }
  50. }
  51. }
  52. if(on==-)for(int i=;i<len;++i)x[i].r/=len;
  53. }
  54. complex x1[N],x2[N];
  55. char str1[N/],str2[N/];
  56. int sum[N];
  57. int main(){
  58. while(~scanf("%s%s",str1,str2)){
  59. int len1 = strlen(str1);
  60. int len2 = strlen(str2),len=;
  61. while(len<len1*||len<len2*)len<<=;
  62. for(int i=;i<len1;++i)
  63. x1[i]=complex(str1[len1--i]-'',);
  64. for(int i=len1;i<len;++i)
  65. x1[i]=complex(,);
  66. for(int i=;i<len2;++i)
  67. x2[i]=complex(str2[len2--i]-'',);
  68. for(int i=len2;i<len;++i)
  69. x2[i]=complex(,);
  70. fft(x1,len,);
  71. fft(x2,len,);
  72. for(int i=;i<len;++i)
  73. x1[i]=x1[i]*x2[i];
  74. fft(x1,len,-);
  75. for(int i=;i<len;++i)
  76. sum[i]=(int)(x1[i].r+0.5);
  77. for(int i=;i<len;++i){
  78. sum[i+]+=sum[i]/;
  79. sum[i]%=;
  80. }
  81. len = len1+len2-;
  82. while(sum[len]<=&&len>)--len;
  83. for(int i=len;i>=;--i)printf("%d",sum[i]);
  84. printf("\n");
  85. }
  86. return ;
  87. }

HDU1402 A * B Problem Plus FFT的更多相关文章

  1. HDU-1402 A * B Problem Plus FFT(快速傅立叶变化)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1402 一般的的大数乘法都是直接模拟乘法演算过程,复杂度O(n^2),对于这题来说会超时.乘法的过程基本 ...

  2. [hdu1402]A * B Problem Plus(FFT模板题)

    解题关键:快速傅里叶变换fft练习. 关于结果多项式长度的确定,首先将短多项式扩展为长多项式,然后扩展为两倍. #include<cstdio> #include<cstring&g ...

  3. hdu 1402 A * B Problem Plus FFT

    /* hdu 1402 A * B Problem Plus FFT 这是我的第二道FFT的题 第一题是完全照着别人的代码敲出来的,也不明白是什么意思 这个代码是在前一题的基础上改的 做完这个题,我才 ...

  4. 【CF954I】Yet Another String Matching Problem(FFT)

    [CF954I]Yet Another String Matching Problem(FFT) 题面 给定两个字符串\(S,T\) 求\(S\)所有长度为\(|T|\)的子串与\(T\)的距离 两个 ...

  5. FFT/NTT模板 既 HDU1402 A * B Problem Plus

    @(学习笔记)[FFT, NTT] Problem Description Calculate A * B. Input Each line will contain two integers A a ...

  6. hdu----(1402)A * B Problem Plus(FFT模板)

    A * B Problem Plus Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Other ...

  7. HDU1402 A * B Problem Plus(FFT)

    http://acm.hdu.edu.cn/showproblem.php?pid=1402 初学FFT. http://www.cnblogs.com/WABoss/p/FFT_Note.html ...

  8. 【FFT】hdu1402 A * B Problem Plus

    FFT板子. 将大整数看作多项式,它们的乘积即多项式的乘积在x=10处的取值. #include<cstdio> #include<cmath> #include<cst ...

  9. A * B Problem Plus(fft)

    题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=1402 hdu_1402:A * B Problem Plus Time Limit: 2000/100 ...

随机推荐

  1. hdu2011

    http://acm.hdu.edu.cn/showproblem.php?pid=2011 #include<iostream> #include<math.h> #incl ...

  2. lintcode 中等题:Evaluate Reverse Polish notation逆波兰表达式求值

    题目 逆波兰表达式求值 在逆波兰表达法中,其有效的运算符号包括 +, -, *, / .每个运算对象可以是整数,也可以是另一个逆波兰计数表达. 样例 ["2", "1&q ...

  3. lintcode:合并区间

    题目: 合并区间 给出若干闭合区间,合并所有重叠的部分. 样例 给出的区间列表 => 合并后的区间列表: [ [ [1, 3], [1, 6], [2, 6], => [8, 10], [ ...

  4. 7、单向一对多的关联关系(1的一方有n的一方的集合属性,n的一方却没有1的一方的引用)

    单向一对多的关联关系 具体体现:1的一方有n的一方的集合的引用,n的一方却没有1的一方的引用 举个例子:顾客Customer对订单Order是一个单向一对多的关联关系.Customer一方有对Orde ...

  5. Failed to allocate memory: 8

    Failed to allocate memory: 8This application has requested the Runtime to terminate it in an unusual ...

  6. Django admin的一些有用定制

    Model实例,myapp/models.py: from django.db import models class Blog(models.Model): name = models.CharFi ...

  7. android的helloworld工程目录学习

    android的helloworld工程目录学习 Android工程的主要目录有src.gen.Android X.X.bin.res等文件夹. 1.     Src文件夹 Src文件夹包含java源 ...

  8. NuGet在2015中的使用

    NuGet Package Restore  https://docs.nuget.org/Consume/Package-Restore 以https://github.com/andburn/hd ...

  9. error LNK2005 new,delete 等已经在LIBCMT.lib(delete.obj) 中定义 错误修正

    http://blog.csdn.net/funnyskyf/article/details/5938597 1>uafxcw.lib(afxmem.obj) : error LNK2005: ...

  10. Android布局详解之一:FrameLayout

      原创文章,如有转载,请注明出处:http://blog.csdn.net/yihui823/article/details/6702273 FrameLayout是最简单的布局了.所有放在布局里的 ...