因为刚学fft,想拿这题练练手,结果WA了个爽= =。

  总结几点犯的错误:

  1.要注意处理前导零的问题。

  2.一定要注意数组大小的问题。(前一个fft的题因为没用到b数组,所以b就没管,这里使用了b数组,结果忘记给其大小乘以4倍了)

  代码如下:

 #include<bits/stdc++.h>
using namespace std;
const double pi = atan(1.0)*;
const int N = 5e4 + ;
typedef long long ll; struct Complex {
double x,y;
Complex(double _x=,double _y=)
:x(_x),y(_y) {}
Complex operator + (Complex &tt) { return Complex(x+tt.x,y+tt.y); }
Complex operator - (Complex &tt) { return Complex(x-tt.x,y-tt.y); }
Complex operator * (Complex &tt) { return Complex(x*tt.x-y*tt.y,x*tt.y+y*tt.x); }
};
Complex a[N*],b[N*];
void fft(Complex *a, int n, int rev) {
// n是(大于等于相乘的两个数组长度)2的幂次 ; 比如长度是5 ,那么 n = 8 2^2 < 5 2^3 > 5
// 从0开始表示长度,对a进行操作
// rev==1进行DFT,==-1进行IDFT
for (int i = ,j = ; i < n; ++ i) {
for (int k = n>>; k > (j^=k); k >>= );
if (i<j) std::swap(a[i],a[j]);
}
for (int m = ; m <= n; m <<= ) {
Complex wm(cos(*pi*rev/m),sin(*pi*rev/m));
for (int i = ; i < n; i += m) {
Complex w(1.0,0.0);
for (int j = i; j < i+m/; ++ j) {
Complex t = w*a[j+m/];
a[j+m/] = a[j] - t;
a[j] = a[j] + t;
w = w * wm;
}
}
}
if (rev==-) {
for (int i = ; i < n; ++ i) a[i].x /= n,a[i].y /= n;
}
} char s[N], t[N];
int c[N*]; int main(){
/*a[0] = Complex(0,0); // a[0]: x的0次项。
a[1] = Complex(1,0);
a[2] = Complex(2,0);
a[3] = Complex(3,0); b[0] = Complex(3,0);
b[1] = Complex(2,0);
b[2] = Complex(1,0);
b[3] = Complex(0,0);
fft(a,8,1);
fft(b,8,1);
for(int i = 0 ; i < 8 ; i ++){
a[i] = a[i] * b[i];
}
fft(a,8,-1);
for(int i = 0 ; i < 8 ; i ++){
cout << i << " " << a[i].x << endl;;
}*/
while(scanf("%s%s",s,t) == )
{
int n = strlen(s), m = strlen(t);
for(int i=;i<n;i++) a[i] = Complex(s[n-i-]-'', );
for(int i=;i<m;i++) b[i] = Complex(t[m-i-]-'', );
int len = n+m-;
int LIM = ;
while(LIM < len) LIM <<= ;
for(int i=n;i<LIM;i++) a[i] = Complex(, );
for(int i=m;i<LIM;i++) b[i] = Complex(, );
fft(a, LIM, );
fft(b, LIM, );
for(int i=;i<LIM;i++) a[i] = a[i] * b[i];
fft(a, LIM, -);
memset(c, , sizeof c);
for(int i=;i<len-;i++)
{
c[i] += (int)(a[i].x + 0.1);
c[i+] += c[i] / ;
c[i] %= ;
}
c[len-] += (int)(a[len-].x + 0.1);
if(c[len-] > )
{
c[len] = c[len-] / ;
c[len-] %= ;
len++;
}
for(int i=len-;i>;i--) if(c[i] == ) len--; else break; // 0 * 345 = 0 instead of 000
for(int i=;i<len/;i++) swap(c[i], c[len-i-]);
for(int i=;i<len;i++) printf("%d",c[i]);
puts("");
}
return ;
}

HDU 1402 A * B Problem Plus ——(大数乘法,FFT)的更多相关文章

  1. HDU 1402 A * B Problem Plus 快速傅里叶变换 FFT 多项式

    http://acm.hdu.edu.cn/showproblem.php?pid=1402 快速傅里叶变换优化的高精度乘法. https://blog.csdn.net/ggn_2015/artic ...

  2. hdu 1402 A * B Problem Plus FFT

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

  3. [hdu1402]大数乘法(FFT模板)

    题意:大数乘法 思路:FFT模板 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 ...

  4. 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 ...

  5. HDU 1402 大数乘法 FFT、NTT

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

  6. HDU - 1402 A * B Problem Plus (FFT实现高精度乘法)

    题意:计算A*B,A,B均为长度小于50000的整数. 这是FFT在大整数相乘中的一个应用,我本来想用NTT做的,但NTT由于取模很可能取炸,所以base必须设得很小,而且效率也比不上FFT. A和B ...

  7. HDU - 1402 A * B Problem Plus FFT裸题

    http://acm.hdu.edu.cn/showproblem.php?pid=1402 题意: 求$a*b$ 但是$a$和$b$的范围可以达到 $1e50000$ 题解: 显然...用字符串模拟 ...

  8. HDU 1402 A * B Problem Plus(FFT)

    Problem Description Calculate A * B.   Input Each line will contain two integers A and B. Process to ...

  9. HDU 1402:A * B Problem Plus

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

随机推荐

  1. Oracle触发器编译错误及解决方案

    错误 TRIGGER **** 编译错误 错误:PLS-00103: 出现符号 "END"在需要下列之一时:        ( begin case declare exit    ...

  2. 如何理解H264 编码

    H264 结构 https://blog.csdn.net/andywang201001/article/details/80274886 H264 源码  https://www.cnblogs.c ...

  3. Node.js 实战(一)之—防灾备措施

    前言 博客系统上线已经3个多月了,中间没有出现过宕机事故,一直稳定运行.自己写的代码还是挺严谨的,小小鼓励一下!上周对云服务器进行了一次内存扩容,扩容后重启了一次服务器.虽然过程很短,但是因重启后导致 ...

  4. py-1 语言介绍

    一.编程与编程语言 1.编程的目的 计算机的发明,是为了用机器取代并解放人力.而编程的目的则是将人类的思想流程按照某种能够被计算机识别的表达方式传递给计算机,从而达到让计算机能够像人脑.电脑一样自动执 ...

  5. Android笔记(四) Activity之间的数据传递

    我们之前使用Intent进行Activity之间的跳转,其实Intent还可以在启动活动的时候传递数据. Intent提供了一系列的putExtra方法以便我们把想要传递的数据暂存在Intent中,待 ...

  6. Win10开启蓝屏信息记录及文件查看位置的方法

    蓝屏,是电脑最常见的故障,一般出现蓝屏时都会显示详细的蓝屏错误信息,方便用户排查故障.但是如果系统未开启蓝屏记录,下文介绍蓝屏日志开启及蓝屏日志文件存放位置.我用的是win10系统 蓝屏日志开启方法步 ...

  7. 这个在Github有52100颗星星的项目,怎么还有人不知道鸭!

    Ta是近两年Docker最为火热的开源项目之一.Docker 开启了容器时代,而Ta则革新了我们对于云计算,软件开发流程,业务平台等等方面的认知. Ta就是Kubernetes,/k(j)uːbəˈn ...

  8. RHEL/CentOS/Fedora各种源(EPEL、Remi、RPMForge、RPMFusion)

    参考:RHEL/CentOS/Fedora各种源(EPEL.Remi.RPMForge.RPMFusion)配置 简介 CentOS 默认自带 CentOS-Base.repo 源, 但官方源中去除了 ...

  9. 2. 软件有很多种,也有各种分类办法: ShrinkWrap (在包装盒子里面的软件,软件在CD/DVD上); Web APP (基于网页的软件); Internal Software (企业或学校或某组织内部的软件); Games (游戏); Mobile Apps (手机应用); Operating Systems (操作系统); Tools

     选取对你最相关的一类软件,  请回答:(web app)  1) 此类软件是什么时候开始出现的, 这些软件是怎么说服你(陌生人)成为他们的用户的?  他们的目标都是盈利么?  他们的目标都是赚取用户 ...

  10. python(动态传参、命名空间、函数嵌套、global和nonlocal关键字)

    一.函数的动态传参 1.*args位置参数动态传参 def chi(*food): print(food) chi("烧烤","火锅","虾吃虾涮&q ...