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 ...
随机推荐
- ubuntu Linux 测试PHP却提示下载文件的解决办法
ubuntu Linux 测试PHP却提示下载文件的解决办法 一般这种情况都是在刚刚开始配置环境时出现的, 输入 sudo a2enmod php5 看提示如果出现“$ This module ...
- 关于float的感悟
给元素设置了float样式后,最终的结果是: 1:这个元素漂浮起来, 2:其他的元素位置可以视为 这个元素不存在 的时候的位置:但是float样式还是对整个页面有所影响 3:float的影响就是他附近 ...
- Pre-Query trigger in Oracle D2k / Oracle Forms
Pre-Query trigger in Oracle D2k / Oracle Forms DescriptionFires during Execute Query or Count Query ...
- JavaScript语法(一)
JavaScript 用法 HTML 中的脚本必须位于 <script> 与 </script> 标签之间. 脚本可被放置在 HTML 页面的 <body> 和 & ...
- web后门top
看到了一个博客 觉得关键点很有用 1)出现频率最高的DDoS后门文件名 abc.php, xl.php, Xml.php, dedetag.class.php, counti.php, plase. ...
- Android——android学习(android目录与AndroidManifest解析)
res目录:存放android项目的各种资源文件 layout:存放界面布局文件 values:存放各种xml格式的资源文件 strings.xml:字符串资源文件: colors.xml:颜色资源文 ...
- iOS - UIColor
前言 NS_CLASS_AVAILABLE_IOS(2_0) @interface UIColor : NSObject <NSSecureCoding, NSCopying> @avai ...
- Linux添加新硬盘自动挂载硬盘
Linux添加新硬盘自动挂载硬盘的具体步骤 1.插入新硬盘,启动Linux服务器,使用fdisk -l 查看硬盘 #fdisk -l Disk /dev/sdb: 1000.2 GB, 1000204 ...
- Linux_常用命令_01
PS:一些不涉及其他软件的操作,OS本来就支持的命令. 1.压缩/解压: 压缩: tar -zcvf /home/android1.6_cmdCompress.tar.gz /root/manifes ...
- [转载] 360分布式存储系统Bada的设计和应用
原文: http://mp.weixin.qq.com/s?__biz=MzAwMDU1MTE1OQ==&mid=208931479&idx=1&sn=1dc6ea4fa28a ...