HDU 1402:A * B Problem Plus
A * B Problem Plus
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 16932 Accepted Submission(s): 3558
Note: the length of each integer will not exceed 50000.
1 2 1000 2
2 2000
还是没有看懂这道题的代码,(;′⌒`)
#include<iostream> #include<stdio.h> #include<algorithm> #include<iomanip> #include<cmath> #include<cstring> #include<vector> #define ll __int64 #define pi acos(-1.0) using namespace std; const int MAX = 200005; //复数结构体 struct complex { double r,i; complex(double R=0,double I=0) { r=R; i=I; } complex operator+(const complex &a) { return complex(r+a.r,i+a.i); } complex operator-(const complex &a) { return complex(r-a.r,i-a.i); } complex operator*(const complex &a) { return complex(r*a.r-i*a.i,r*a.i+i*a.r); } }; /* *进行FFT和IFFT前的反转变换 *位置i和i的二进制反转后位置互换,(如001反转后就是100) *len必须去2的幂 */ void change(complex x[],int len) { int i,j,k; for(i = 1, j = len/2; i <len-1; i++) { if (i < j) swap(x[i],x[j]); //交换互为小标反转的元素,i<j保证交换一次 //i做正常的+1,j做反转类型的+1,始终i和j是反转的 k = len/2; while (j >= k) { j -= k; k /= 2; } if (j < k) j += k; } } /* *做FFT *len必须为2^n形式,不足则补0 *on=1时是DFT,on=-1时是IDFT */ void fft (complex x[],int len,int on) { change(x,len); for (int i=2; i<=len; i<<=1) { complex wn(cos(-on*2*pi/i),sin(-on*2*pi/i)); for (int j=0; j<len; j+=i) { complex w(1,0); for (int k=j; k<j+i/2; k++) { complex u = x[k]; complex t = w*x[k+i/2]; x[k] = u+t; x[k+i/2] = u-t; w = w*wn; } } } if (on == -1) for (int i=0; i<len; i++) x[i].r /= len; } complex x1[MAX],x2[MAX]; char str1[MAX/2],str2[MAX/2]; ll num[MAX],sum[MAX]; int main() { int i,len1,len2,len; while(scanf("%s%s",str1,str2)!=EOF) { len1 = strlen(str1); len2 = strlen(str2); len = 1; while (len < 2*len1 || len < 2*len2) len<<=1; for (i=0; i<len1; i++) x1[i] = complex(str1[len1-1-i]-'0',0); for (i=len1; i<len; i++) x1[i] = complex(0,0); for (i=0; i<len2; i++) x2[i] = complex(str2[len2-1-i]-'0',0); for (i=len2; i<len; i++) x2[i] = complex(0,0); fft(x1,len,1); fft(x2,len,1); for (i=0; i<len; i++) x1[i] = x1[i]*x2[i]; fft(x1,len,-1); for (i=0; i<len; i++) sum[i] = (int)(x1[i].r+0.5); for (i=0; i<len; i++) { sum[i+1]+=sum[i]/10; sum[i]%=10; } len = len1+len2-1; while (sum[len]<=0 && len>0) len--; for (i=len; i>=0; i--) printf("%c",(char)sum[i]+'0'); printf("\n"); } return 0; }
HDU 1402:A * B Problem Plus的更多相关文章
- hdu 1402 A * B Problem Plus FFT
/* hdu 1402 A * B Problem Plus FFT 这是我的第二道FFT的题 第一题是完全照着别人的代码敲出来的,也不明白是什么意思 这个代码是在前一题的基础上改的 做完这个题,我才 ...
- HDU - 1402 A * B Problem Plus FFT裸题
http://acm.hdu.edu.cn/showproblem.php?pid=1402 题意: 求$a*b$ 但是$a$和$b$的范围可以达到 $1e50000$ 题解: 显然...用字符串模拟 ...
- HDU 1402 A * B Problem Plus 快速傅里叶变换 FFT 多项式
http://acm.hdu.edu.cn/showproblem.php?pid=1402 快速傅里叶变换优化的高精度乘法. https://blog.csdn.net/ggn_2015/artic ...
- HDU 1402 A * B Problem Plus(FFT)
Problem Description Calculate A * B. Input Each line will contain two integers A and B. Process to ...
- 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 ...
- hdu 1402 A * B Problem Plus (FFT模板)
A * B Problem Plus Problem Description Calculate A * B. Input Each line will contain two integers A ...
- FFT(快速傅立叶变换):HDU 1402 A * B Problem Plus
Calculate A * B. Input Each line will contain two integers A and B. Process to end of file. Note: th ...
- HDU 1402 A * B Problem Plus (FFT模板题)
FFT模板题,求A*B. 用次FFT模板需要注意的是,N应为2的幂次,不然二进制平摊反转置换会出现死循环. 取出结果值时注意精度,要加上eps才能A. #include <cstdio> ...
- HDU - 1402 A * B Problem Plus (FFT实现高精度乘法)
题意:计算A*B,A,B均为长度小于50000的整数. 这是FFT在大整数相乘中的一个应用,我本来想用NTT做的,但NTT由于取模很可能取炸,所以base必须设得很小,而且效率也比不上FFT. A和B ...
随机推荐
- 错误是无法将“XXX”转换为“System.CompenentModel.Design.Serialization.InstanceDescrip”问题的解决办法
发生原因: 出现这个问题的原因是两次编译生成的程序集的版本一样,导致VS的窗体设计器没有获取到最新的运行时对象,而出现的错误. 解决办法: 修改项目的配置信息,使其每次编译的时候都生成不同的版本. 在 ...
- vs2015社区版不支持installshield
开始学习vs了 下一步就是在这个平台上提升技术咯. 写了老师上课讲的算法 生成了个VB程序结果不能在别的电脑上运行 .幸好我自己测试了下.要是直接拿去学校不是很~ 然后我就想到当初接触易语言时候的搞静 ...
- Python学习总结2:raw_input() 与 input()
参考http://www.cnblogs.com/way_testlife/archive/2011/03/29/1999283.html 1. 输入数据要求 raw_input() 直接读取控制台的 ...
- Java基础(30):String对象的常用方法与实例(String类)
Java 中 String 类的常用方法 Ⅰ String 类提供了许多用来处理字符串的方法,例如,获取字符串长度.对字符串进行截取.将字符串转换为大写或小写.字符串分割等,下面我们就来领略它的强大之 ...
- javascript 内置对象
什么是对象 javascript中的所有事物都是对象:字符串 数组 数值 函数... 每个对象都带有属性和方法 javascript允许自定义对象 自定义对象: 定义并创建对象实例 使 ...
- HDU 4512 吉哥系列故事——完美队形(LCIS)
Problem Description 吉哥这几天对队形比较感兴趣. 有一天,有n个人按顺序站在他的面前,他们的身高分别是h[1], h[2] ... h[n],吉哥希望从中挑出一些人,让这些人形成一 ...
- struts_24_基于XML校验的规则、特点
当为某个action提供了ActionClassName-validation.xml和ActionClassName-ActionName-validation.xml两种规则的校验文件时,系统按下 ...
- Android SDK Manager更新报错
错误log: Fetching https://dl-ssl.google.com/android/repository/addons_list-.xml Fetched Add-ons List s ...
- HttpHandler和ashx要实现IRequiresSessionState接口才能访问Session信息(转载)
通常我们经常,通过session判定用户是否登录.还有一些临时的.重要的数据也尝尝存放在Session中. 在页面我们很容易的得到Session的值,但在类中就会遇到一些问题.也知道通过下面的方法得到 ...
- 记一个由MemCached引发的性能问题
最近有个项目用loadrunner做了压力测试,发现并发量还不到200服务器就支撑不住了.boss那边紧急开会,说此项目最近3个月内将有100家中大型公司用于校园招聘工作,如果这个问题不解决公司有可能 ...