hdu----(1402)A * B Problem Plus(FFT模板)
A * B Problem Plus
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 12665 Accepted Submission(s): 2248
Note: the length of each integer will not exceed 50000.
2
1000
2
2000
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
using namespace std;
#define N 50500*2
const double PI=acos(-1.0);
struct Vir
{
double re,im;
Vir(double _re=.,double _im=.):re(_re),im(_im){}
Vir operator*(Vir r) { return Vir(re*r.re-im*r.im,re*r.im+im*r.re);}
Vir operator+(Vir r) { return Vir(re+r.re,im+r.im);}
Vir operator-(Vir r) { return Vir(re-r.re,im-r.im);}
};
void bit_rev(Vir *a,int loglen,int len)
{
for(int i=;i<len;++i)
{
int t=i,p=;
for(int j=;j<loglen;++j)
{
p<<=;
p=p|(t&);
t>>=;
}
if(p<i)
{
Vir temp=a[p];
a[p]=a[i];
a[i]=temp;
}
}
}
void FFT(Vir *a,int loglen,int len,int on)
{
bit_rev(a,loglen,len); for(int s=,m=;s<=loglen;++s,m<<=)
{
Vir wn=Vir(cos(*PI*on/m),sin(*PI*on/m));
for(int i=;i<len;i+=m)
{
Vir w=Vir(1.0,);
for(int j=;j<m/;++j)
{
Vir u=a[i+j];
Vir v=w*a[i+j+m/];
a[i+j]=u+v;
a[i+j+m/]=u-v;
w=w*wn;
}
}
}
if(on==-)
{
for(int i=;i<len;++i){
a[i].re/=len;
a[i].im/=len;
}
}
}
char a[N*],b[N*];
Vir pa[N*],pb[N*];
int ans[N*];
int main ()
{
while(scanf("%s%s",a,b)!=EOF)
{
int lena=strlen(a);
int lenb=strlen(b);
int n=,loglen=;
while(n<lena+lenb) n<<=,loglen++;
for(int i=,j=lena-;i<n;++i,--j)
pa[i]=Vir(j>=?a[j]-'':.,.);
for(int i=,j=lenb-;i<n;++i,--j)
pb[i]=Vir(j>=?b[j]-'':.,.);
memset(ans,,sizeof(int)*(n+));
FFT(pa,loglen,n,);
FFT(pb,loglen,n,);
for(int i=;i<n;++i)
pa[i]=pa[i]*pb[i];
FFT(pa,loglen,n,-); for(int i=;i<n;++i)
ans[i]=pa[i].re+0.5;
for(int i=;i<n;++i)
{
ans[i+]+=ans[i]/;
ans[i]%=;
}
int pos=lena+lenb-;
for(;pos>&&ans[pos]<=;--pos) ;
for(;pos>=;--pos)
printf("%d",ans[pos]);
puts("");
}
return ;
}
hdu----(1402)A * B Problem Plus(FFT模板)的更多相关文章
- HDU 1402 A * B Problem Plus (FFT模板题)
FFT模板题,求A*B. 用次FFT模板需要注意的是,N应为2的幂次,不然二进制平摊反转置换会出现死循环. 取出结果值时注意精度,要加上eps才能A. #include <cstdio> ...
- 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求高精度乘法)
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,A,B均为长度小于50000的整数. 这是FFT在大整数相乘中的一个应用,我本来想用NTT做的,但NTT由于取模很可能取炸,所以base必须设得很小,而且效率也比不上FFT. A和B ...
- P1919 【模板】A*B Problem升级版 /// FFT模板
题目大意: 给定l,输入两个位数为l的数A B 输出两者的乘积 FFT讲解 这个讲解蛮好的 就是讲解里面贴的模板是错误的 struct cpx { double x,y; cpx(double _x= ...
- hdu 1402 A * B Problem Plus (FFT模板)
A * B Problem Plus Problem Description Calculate A * B. Input Each line will contain two integers A ...
- 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 ...
- 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 ...
随机推荐
- UVA 10453 十七 Make Palindrome
Make Palindrome Time Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld & %llu Submit St ...
- Using Text_IO To Read Files in Oracle D2k
Suppose you want to read a file from D2k client and want to store its content in Oracle database. Bu ...
- GBrowse配置相关资料
GBrowse配置相关资料(形状.颜色.配置.gff3) http://gmod.org/wiki/Glyphs_and_Glyph_Optionshttp://gmod.org/wiki/GBrow ...
- Oracle数据库名、实例名、数据库域名、数据库服务名、全局数据库名的辨析
我也是看着各位大婶的博客然后一点点的来学习,不求全会,留个印象 数据库名 数据库名就是一个数据库的标识,用参数DB_NAME表示. 如果一台机器上安装了多个数据库,那么每一个数据库都有一个数据库名. ...
- ServiceStack.OrmLite 6 学习笔记 查
查 根据id var result = db.SingleById<Poco>(1); 根据字段 var customer = db.Single<Customer>(new ...
- 通知(NSNotificationCenter)
// 监听加载更多的通知 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(loadMoreDeals ...
- JAVA运算符和优先级
1.算术运算符: ++ 和 -- 既可以出现在操作数的左边,也可以出现在右边,但结果是不同,如: ①int a=5: int b=a++: #先把a赋给b,a再自增 ②int a=5: int b=+ ...
- JVM 1.类的加载、连接、初始化
Java类的加载是由类加载器来完成的,过程如下: 首先,加载是把硬盘.网络.数据库等的class文件中的二进制数据加载到内存的过程,然后会在Java虚拟机的运行时数据区的堆区创建一个Class对象,用 ...
- Domion OA 日记
我现在使用的是IBM的 Lotus Dimion 8.5 以下内容是个人的浅显了解,在此记录下,已作为后续记录的翻看 第一次接触文档型数据库,确实颠覆了我对数据模型的认知,我之前一直用sql的 文档型 ...
- mac系统如何进行剪切
来源: http://jingyan.baidu.com/article/1612d5007f76e7e20e1eeeca.html 分步阅读 mac os x下没有像windows中现成的“剪切”命 ...