HDU 1402 A*B
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define ms(s,a) memset(s,a,sizeof(s))
#define debug(x) cout<<"< "#x" = "<<x<<" >\n"
const double pi=3.1415926536;
const int maxn=3e5+5;
complex<double> a[maxn],b[maxn],c[maxn];
void rearrange(complex<double> x[],int n)
{
for(int i=1,j=n/2;i<n;++i)
{
if(i<j)swap(x[i],x[j]);
int tmp=n/2;
while(tmp&&j>=tmp){j-=tmp;tmp/=2;}
if(j<tmp)j+=tmp;
}
}
void fft(complex<double> x[],int n,int sig)
{
rearrange(x,n);
for(int i=2;i<=n;i*=2)
{
for(int j=0;j<n;j+=i)
{
for(int k=j;k<j+i/2;++k)
{
complex<double> e=x[k],o=x[k+i/2],w=exp(complex<double>(0,sig*2.*pi*(k-j)/i));
x[k]=e+w*o;
x[k+i/2]=e-w*o;
}
}
}
if(sig==-1)
{
for(int i=0;i<n;++i)x[i]/=n;
}
}
int main()
{
char A[50005],B[50005];
while(~scanf("%s%s",A,B))
{
int la=strlen(A),lb=strlen(B);
int tot=1;
while(tot<la+lb-1)tot*=2;
for(int i=0;i<tot;++i)
{
int tmp=0;
if(i<la)tmp=A[i]-'0';
a[i]=tmp;
}
for(int i=0;i<tot;++i)
{
int tmp=0;
if(i<lb)tmp=B[i]-'0';
b[i]=tmp;
}
fft(a,tot,1);fft(b,tot,1);
for(int i=0;i<tot;++i)c[i]=a[i]*b[i];
fft(c,tot,-1);
//for(int i=0;i<la+lb-1;++i)printf("%lf,",c[i].real());
//printf("\n");
int ans[maxn],top=la+lb-2;
memset(ans,0,sizeof ans);
for(int i=0;i<tot;++i)
{
ans[i]=ans[i]+c[la+lb-2-i].real()+0.5;
if(i>la+lb-3&&ans[i]==0)break;
if(ans[i]>9)
{
ans[i+1]=ans[i]/10;
ans[i]%=10;
if(i>la+lb-3)top++;
}
}
while(top>0&&ans[top]==0)top--;
while(top>-1)printf("%d",ans[top--]);
printf("\n");
}
}
HDU 1402 A*B的更多相关文章
- hdu 1402 A * B Problem Plus FFT
/* hdu 1402 A * B Problem Plus FFT 这是我的第二道FFT的题 第一题是完全照着别人的代码敲出来的,也不明白是什么意思 这个代码是在前一题的基础上改的 做完这个题,我才 ...
- HDU 1402 FFT 大数乘法
$A * B$ FFT模板题,找到了一个看起来很清爽的模板 /** @Date : 2017-09-19 22:12:08 * @FileName: HDU 1402 FFT 大整数乘法.cpp * ...
- A * B Problem Plus HDU - 1402 (FFT)
A * B Problem Plus HDU - 1402 (FFT) Calculate A * B. InputEach line will contain two integers A and ...
- fft模板 HDU 1402
// fft模板 HDU 1402 #include <iostream> #include <cstdio> #include <cstdlib> #includ ...
- 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
http://acm.hdu.edu.cn/showproblem.php?pid=1402 fft做O(nlog(n))大数乘法,kuangbin的模板 #include <stdio.h&g ...
- HDU 1402 fft 模板题
题目就是求一个大数的乘法 这里数字的位数有50000的长度,按平时的乘法方式计算,每一位相乘是要n^2的复杂度的,这肯定不行 我们可以将每一位分解后作为系数,如153 = 1*x^2 + 5*x^1 ...
- 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
A * B Problem Plus Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Other ...
随机推荐
- 001_Chrome 76支持原生HTML 图片懒加载Lazy loading
Table Of Content 什么是懒加载? 语法参数及使用方式? 有哪些特点? 与js有关的实践 什么是懒加载? 技术背景 Web应用需要经常向后台服务器请求资源(通过查询数据库,是非常耗时耗资 ...
- webpack4.0(01.基础配置和初识)
1.什么是webpack? 2.webpack可以做什莫? 代码转换.文件优化.代码分割.模块合并.自动刷新.代码校验.自动发布 3.我们要学习webpack的什么? 4.使用webpack 1.首先 ...
- websocket聊天室
目录 websocket方法总结 群聊功能 基于websocket聊天室(版本一) websocket方法总结 # 后端 3个 class ChatConsumer(WebsocketConsumer ...
- Java第十一天,final关键字的使用规则
final 最终的.不可改变的. 用法: 修饰类 修饰方法 修饰成员变量 修饰局部变量 注意事项: 对于类和方法,final和abstract不能同时修饰使用. 对于基本类型来说,不可变是说值不可变: ...
- 安卓开发学习日记 DAY4——Button,ImageButton
Button与ImageButton基本类似 也有类似于TextView和ImageView的区别 这里需要注意的是: 在你定义text属性的内容时,最好是在Values文件下的String.xml中 ...
- python连接mysql中文数据编码
系统是win7 x64 Python 2.7.6的site.py里面编码设定为 utf-8 py文件首行指定 #coding:utf-8 MySQL 5.5.38安装时指定代码为utf-8 peewe ...
- android性能测试--CPU、内存
- 游戏开服 报一些 ip 设置 数据格式的异常,但断点明明都是数字 没问题的
游戏服开始起服,结果报乱七八招的错误,先 ccs 那 ip 有问题,我给直接注释掉了:然后又 报 KeyValueDictCache 中 ips 设置有问题,都是报格式错误,结果我断点明明都是数字结 ...
- 类 文件 右下角呈现 红色小圆圈,里面有一个J 标记
intellj(idea) 项目中类 文件 右下角呈现 红色小圆圈,里面有一个J 标记,表明此为 未设置为源文件,没有编译,本来应该是属于源文件的,结果现在没有被标记为源文件,也就没法编译了.
- sql server临时删除/禁用非聚集索引并重新创建加回/启用的简便编程方法研究对比
前言: 由于新型冠状病毒影响,博主(zhang502219048)在2020年1月份从广东广州工作地回到广东揭阳产业转移工业园磐东街道(镇里有阳美亚洲玉都.五金之乡,素以“金玉”闻名)老家后,还没过去 ...