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 ...
随机推荐
- 深入解读ES6系列(四)
来自老曾es6的前言: 哈喽小伙伴们,爱说'废'话的Z又回来了,欢迎来到Super IT曾的博客时间,上一节说了字符串,面向对象以及json的知识,这一节我们继续我们知识的海洋,一起奋斗不秃头!不足的 ...
- div实现富文本编辑框
ocument.execCommand()方法处理Html数据时常用语法格式如下:document.execCommand(sCommand[,交互方式, 动态参数]) 其中:sCommand为指令参 ...
- 浅谈动态规划(Dynamic Programming)
利用Leetcode#198打劫家舍 浅谈动态规划 Origin:https://leetcode-cn.com/problems/house-robber/ 题目本身不难,就是一个动态规划的问题.在 ...
- spring官方为什么放弃spring social项目及替代方案
spring social 1.6之后官方不在维护该项目, spring boot 2.x之后也不在提供spring social的 Autoconfiguration. 原因: https://sp ...
- go 名词备注
1.Protobuf Google Protocol Buffer(简称 Protobuf)是一种轻便高效的结构化数据存储格式,平台无关.语言无关.可扩展,可用于通讯协议和数据存储等领域.
- 汇编 RET 和 CALL
https://blog.csdn.net/u013018721/article/details/51264199 1.我们先来实践一下 ret 指令 DATA SEGMENT A DB 12H B ...
- "文本"组件:<text> —— 快应用原生组件
 <template> <div class="container"> <text>H-UI</text> </div> ...
- Python Request-学习笔记(1)
#导入Requests模块:import requests # 然后,尝试获取某个网页.返回的是reaponse对象,可以从这个对象中获取所有我们想要的信息.response = requests.g ...
- cmake添加版本号
vVersion.cmake文件内容如下: #vversion.cmake #vDateTime string(TIMESTAMP vDateTime "%Y%m%d-%H%M%S" ...
- PHP单例模式及应用场
设计模式?听起来很高大上?的确是这样的.设计模式就是组织代码的方式,也就是说代码不再是一条条的往下执行,按照前人总结的行之有效的方法,更有效的来组织代码,这样效率更高,而且看起来也清晰有序. php单 ...