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

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

Note: the length of each integer will not exceed 50000.

 
Output
For each case, output A * B in one line.
 
Sample Input
1
2
1000
2
 
Sample Output
2
2000
 
Author
DOOM III
快速傅里叶转换算法.....
代码:
 #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模板)的更多相关文章

  1. HDU 1402 A * B Problem Plus (FFT模板题)

    FFT模板题,求A*B. 用次FFT模板需要注意的是,N应为2的幂次,不然二进制平摊反转置换会出现死循环. 取出结果值时注意精度,要加上eps才能A. #include <cstdio> ...

  2. hdu 1402 A * B Problem Plus FFT

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

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

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

  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 A * B Problem Plus (FFT实现高精度乘法)

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

  6. P1919 【模板】A*B Problem升级版 /// FFT模板

    题目大意: 给定l,输入两个位数为l的数A B 输出两者的乘积 FFT讲解 这个讲解蛮好的 就是讲解里面贴的模板是错误的 struct cpx { double x,y; cpx(double _x= ...

  7. hdu 1402 A * B Problem Plus (FFT模板)

    A * B Problem Plus Problem Description Calculate A * B. Input Each line will contain two integers A ...

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

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

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

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

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

随机推荐

  1. vs2012 提示 未能正确加载 "Visual C++ Language Manager Package" 包 的解决办法

    1.点击vs2012菜单栏 工具-> Visual Studio 命令提示 打开命令窗口 2.输入命令 "devenv /Setup" 3.重新打开vs2012

  2. ubuntu vi/vim编辑器必知必会

    转载出处:http://blog.csdn.net/xiajun07061225/article/details/7039413 一.我们为什么要学习vim编辑器? Linux的命令行界面下面有非常多 ...

  3. Java开发中经典的小实例-(if(参数){}else{})

    import java.util.Scanner; public class Calculate {    public static void main(String[] args) {       ...

  4. [Effective Java]第四章 类和接口

    声明:原创作品,转载时请注明文章来自SAP师太技术博客( 博/客/园www.cnblogs.com):www.cnblogs.com/jiangzhengjun,并以超链接形式标明文章原始出处,否则将 ...

  5. Android SDK 更新镜像服务器

    搞个新的电脑,新环境下,SDK总是更新不成功.找了一下,发现有国内的镜像,记录保存一下. Android Tools Android SDK在线更新镜像服务器    中国科学院开源协会镜像站地址:   ...

  6. hdu5816 卡特兰数+dp

    题意:共n张无中生有,m张攻击牌.每张攻击牌攻击力已知,敌方有p点血.随机洗牌.游戏开始,己方抽取一张手牌,若是无中生有则可再抽两张牌.求能在第一回合内将敌方杀死的概率. n+m <= 20, ...

  7. js原型链闭包作用域链-Tom

    1.原型相当于Java.C++里面的父类,由封装公有属性及方法而产生,子类可以继承. 原型继承实现(函数的原型属性指向原型函数一个实例对象,函数的原型的构造函数指向函数本身) 1)eg:原型链 fun ...

  8. Forbidden You don't have permission to access / on this server. You don't have permission to access /phpmyadmin/ on this server. 解决办法

    Forbidden  You don't have permission to access / on this server.   解决办法 打开 httpd.conf 文件, 将 #   onli ...

  9. Oracle一列的多行数据拼成一行显示字符

    Oracle一列的多行数据拼成一行显示字符   oracle 提供了两个函数WMSYS.WM_CONCAT 和 ListAgg函数.    www.2cto.com   先介绍:WMSYS.WM_CO ...

  10. commons-logging日志系统

    日志的重要性是随着系统的膨胀而显现的,在一个庞大的系统中查错没有各种日志信息    是寸步难行的.所以在系统加入日志是必须的. 最原始的日志方式,就是在程序的适当地方添加System.out.prin ...