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 ...
随机推荐
- SetWindowHookEx 做消息响应
HHOOK g_Hook = NULL; LRESULT CALLBACK CallWndProc( _In_ int nCode, _In_ WPARAM wParam, _In_ LPARAM l ...
- Linux安装配置JDK
如果想看Windows下的安装,请访问此链接: http://www.cnblogs.com/yoyotl/p/5101321.html 1. 去官网下载Linux版本的jdk安装包,(我下载的是ta ...
- 错题集锦(二) -- Java专项
错题集锦(二) -- Java专项 标签(空格分隔): 找工作 JVM的内存模型 线程共享: 堆(Heap):主要存放一些对象实例 方法区(Method Area / Non-Heap):用于存储已被 ...
- 重命名myclipse中web项目名称的过程
1 打开 myclipse2 最顶层项目上右键,Refactor,新名,3 最顶层项目上右键,propterties, MyEclipse, Web, context-root: /新名4 替换 .c ...
- EasyUI--messager
1. alert 方法 <script type="text/javascript"> $( function() { $.messager.alert("调 ...
- 5.Primitive, Reference, and Value Types
1.Programming Language Primitive Types primitive types:Any data types the compiler directly supports ...
- SLAM reference
Technical website: OpenSlam: http://openslam.org/ MRPT: http://www.mrpt.org/ Monocular SLAM: https:/ ...
- 自定义CSS博客(转)
摘自:http://www.cnblogs.com/libaoheng/archive/2012/03/19/2406836.html 前 言 一个好的阅读体验,对技术博客来说,也许算是锦上添花.入 ...
- Perfection Kills
<!doctype html> <html> <head> <meta charset="utf-8"> <title> ...
- 笔记本_thinkpad_e40_FN
1. 开机时按F10进入bios 然后在 bios 中选择 system configuration,看一下其中的 action keys mode .如果此选项后面为 enable 的话,是不需要按 ...