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 ...
随机推荐
- C/C++知识总结 一 C/C++常识概述
C/C++常识概述 程序与计算机语言 C/C++简介与发展 C/C++异同 C/C++编译特点 学习编程建议 程序与计算机语言 程序:是一组计算机能识别和执行.预先编好的一些指令操作合集. 计算机语言 ...
- Face The Right Way POJ - 3276(区间)
Farmer John has arranged his N (1 ≤ N ≤ 5,000) cows in a row and many of them are facing forward, li ...
- 《Three.js 入门指南》1.3 - Three JS 功能预览
[部分中英文对照] Cameras(照相机,控制投影方式) Camera OrthographicCamera 正交相机 PerspectiveCamera 透视相机 Core(核心对象) Buffe ...
- UnboundLocalError,探讨Python中的绑定
绑定 将python闭包之前,先梳理一下闭包中的绑定操作. 先看看2个相关的错误 NameError 和UnboundLocalError When a name is not found at al ...
- PTA数据结构与算法题目集(中文) 7-36 社交网络图中结点的“重要性”计算 (30 分)
PTA数据结构与算法题目集(中文) 7-36 社交网络图中结点的“重要性”计算 (30 分) 7-36 社交网络图中结点的“重要性”计算 (30 分) 在社交网络中,个人或单位(结点)之间通过某 ...
- Linux系统安装java jdk
1)下载地址: https://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html 我这里下载的是 ...
- readthedocs网托管持多语言文档
希望在readthedocs上创建支持多语言的文档,效果类似: 通过语言选项,可以切到到不同的语言版本:实现这个目标包含两个主要步骤: 在本地对文档进行翻译 在readthedocs.org上配置翻译 ...
- 【高并发】你知道吗?大家都在使用Redisson实现分布式锁了!!
写在前面 忘记之前在哪个群里有朋友在问:有出分布式锁的文章吗-@冰河?我的回答是:这周会有,也是[高并发]专题的.想了想,还是先发一个如何使用Redisson实现分布式锁的文章吧?为啥?因为使用Red ...
- 2017蓝桥杯贪吃蛇(C++C组)
原题: 贪吃蛇长度+-------------------------------------------------+| ...
- C++11中的四种类型转换
static_cast 基础数据类型转换(基本类型) 同一继承体系中类型的转换(父子类型) 任意类型与空指针(void *)之间的转换(指针类型) dynamic_cast 执行派生类指针或引用与基类 ...