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 ...
随机推荐
- JVM基础结构与字节码执行引擎
JVM基础结构 JVM内部结构如下:栈.堆. 栈 JVM中的栈主要是指线程里面的栈,里面有方法栈.native方法栈.PC寄存器等等:每个方法栈是由栈帧组成的:每个栈帧是由局部变量表.操作数栈等组成. ...
- 【PHP】流程控制
一. 顺序结构 a) PHP的脚本从上到下,从左往右的执行顺序就是顺序结构! 二. 分支结构 a) 单一的分支结构 If ( 条件表达式 ) { 程序体: } 执行过程 ...
- MyBatis(六):SqlSession执行源码分析
SqlSession执行源码分析 针对以下代码 public class MybatisUtils { private static SqlSessionFactory sqlSessionFacto ...
- python 爬虫:学爬虫必学的正则表达式
文章更新于:2020-03-30 一.语法格式 1.非打印字符 操作符 说明 实例 \cx 匹配由x指明的控制字符 \cM 匹配一个 Control-M 或回车符.x 的值必须为 A-Z 或 a-z ...
- 玩转redis-延时消息队列
上一篇基于redis的list实现了一个简单的消息队列:玩转redis-简单消息队列 源码地址 使用demo 产品经理经常说的一句话,我们不光要有X功能,还要Y功能,这样客户才能更满意.同样的,只有简 ...
- 详解java访问修饰符
详解java访问修饰符 为了防止初学者看到因为专业的术语而感觉晦涩难懂,我接下来尽量用生动比喻的说法来解释!首先第一点,我们来讲讲什么叫修饰符!看看这个名称,想想他的意思.修饰符!修饰符!,就是用来修 ...
- 抓包——HTTP分析
1.什么是HTTP请求(底层使用scoket TCP技术) HTTP是超文本传输协议.底层使用的scoket tcp长连接.基于请求和响应 同步请求. 2.重定向底层: 重定向原理:为什么会产生 ...
- django->基本操作和新建项目常用配置
一.安装django pip install django==2.1.5 -U #安装django/升级最新版本 二.创建.启动django项目 django-admin startproject m ...
- matplotlib Transform
2020-04-09 15:09:02 -- Edit by yangray Transform 类是TransformNode的子类,它是所有执行变换的TransformNode的实例的基类.所有非 ...
- Codeup 25594 Problem H 例题5-8 Fibonacci数列
题目描述 输入一个正整数n,求Fibonacci数列的第n个数.Fibonacci数列的特点:第1,2个数为1,1.从第3个数开始,概述是前面两个数之和.即: 1,1,2,3,5,8,13,21 - ...