Description

给出两个n位10进制整数x和y,你需要计算x*y。

Input

第一行一个正整数n。第二行描述一个位数为n的正整数x。第三行描述一个位数为n的正整数y。

Output

输出一行,即x*y的结果。

Sample Input

1
3
4

Sample Output

12

数据范围:
n<=60000

HINT

 

Source

FFT裸题

具体见算导

code:

 #include<cstdio>
#include<iostream>
#include<cmath>
#include<cstring>
#include<algorithm>
#define maxn 131072
#define pi 3.14159265358979323846
using namespace std;
char ch;
int m,n,ans[maxn];
bool ok;
struct comp{
double rea,ima;
void clear(){rea=ima=;}
comp operator +(const comp &x){return (comp){rea+x.rea,ima+x.ima};}
comp operator -(const comp &x){return (comp){rea-x.rea,ima-x.ima};}
comp operator *(const comp &x){return (comp){rea*x.rea-ima*x.ima,rea*x.ima+ima*x.rea};}
}a[maxn],b[maxn],c[maxn],tmp[maxn],w,wn;
void read(int &x){
for (ok=,ch=getchar();!isdigit(ch);ch=getchar()) if (ch=='-') ok=;
for (x=;isdigit(ch);x=x*+ch-'',ch=getchar());
if (ok) x=-x;
}
void read(comp *a){
for (int i=m-;i>=;i--){
for (ch=getchar();!isdigit(ch);ch=getchar());
a[i].rea=ch-'';
}
}
void write(int *a){
int i;
for (i=n-;i>=&&!a[i];i--);
if (i<){puts("");return;}
for (;i>=;i--) printf("%d",(int)a[i]);
puts("");
}
void fft(comp *a,int st,int siz,int step,int op){
if (siz==) return;
fft(a,st,siz>>,step<<,op),fft(a,st+step,siz>>,step<<,op);
int x=st,x1=st,x2=st+step;
w=(comp){,},wn=(comp){cos(op**pi/siz),sin(op**pi/siz)};
for (int i=;i<(siz>>);i++,x+=step,x1+=(step<<),x2+=(step<<),w=w*wn)
tmp[x]=a[x1]+(w*a[x2]),tmp[x+(siz>>)*step]=a[x1]-(w*a[x2]);
for (int i=st;siz;i+=step,siz--) a[i]=tmp[i];
}
int main(){
read(m),n=;
while (n<(m<<)) n<<=;
read(a),read(b);
fft(a,,n,,),fft(b,,n,,);
for (int i=;i<n;i++) c[i]=a[i]*b[i];
fft(c,,n,,-);
for (int i=;i<n;i++) ans[i]=(int)round(c[i].rea/(1.0*n));
for (int i=;i<n;i++) ans[i+]+=ans[i]/,ans[i]%=;
write(ans);
system("pause");
return ;
}

FFT快速傅立叶的更多相关文章

  1. BZOJ 2179: FFT快速傅立叶

    2179: FFT快速傅立叶 Time Limit: 10 Sec  Memory Limit: 259 MBSubmit: 2923  Solved: 1498[Submit][Status][Di ...

  2. 【bzoj2179】FFT快速傅立叶 FFT模板

    2016-06-01  09:34:54 很久很久很久以前写的了... 今天又比较了一下效率,貌似手写复数要快很多. 贴一下模板: #include<iostream> #include& ...

  3. 【BZOJ 2179】 2179: FFT快速傅立叶 (FFT)

    2179: FFT快速傅立叶 Time Limit: 10 Sec  Memory Limit: 259 MBSubmit: 3308  Solved: 1720 Description 给出两个n位 ...

  4. bzoj 2179: FFT快速傅立叶 -- FFT

    2179: FFT快速傅立叶 Time Limit: 10 Sec  Memory Limit: 259 MB Description 给出两个n位10进制整数x和y,你需要计算x*y. Input ...

  5. 【BZOJ2179】FFT快速傅立叶

    [BZOJ2179]FFT快速傅立叶 Description 给出两个n位10进制整数x和y,你需要计算x*y. Input 第一行一个正整数n. 第二行描述一个位数为n的正整数x. 第三行描述一个位 ...

  6. [bzoj2179]FFT快速傅立叶_FFT

    FFT快速傅立叶 bzoj-2179 题目大意:给出两个n位10进制整数x和y,你需要计算x*y. 注释:$1\le n\le 6\times 10^4$. 想法: $FFT$入门题. $FFT$实现 ...

  7. 【CodeVS 3123】高精度练习之超大整数乘法 &【BZOJ 2197】FFT快速傅立叶

    第一次写法法塔,,,感到威力无穷啊 看了一上午算导就当我看懂了?PS:要是机房里能有个清净的看书环境就好了 FFT主要是用了巧妙的复数单位根,复数单位根在复平面上的对称性使得快速傅立叶变换的时间复杂度 ...

  8. BZOJ 2179 FFT快速傅立叶 题解

    bzoj 2179 Description 给出两个n位10进制整数x和y,你需要计算x*y. [题目分析] 高精裸题.练手. [代码] 1.手动高精 #include<cstdio> # ...

  9. FFT快速傅立叶变换的工作原理

    实数DFT,复数DFT,FFTFFT是计算DFT的快速算法,但是它是基于复数的,所以计算实数DFT的时候需要将其转换为复数的格式,下图展示了实数DFT和虚数DFT的情况,实数DFT将时域中N点信号转换 ...

  10. HDU-1402 A * B Problem Plus FFT(快速傅立叶变化)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1402 一般的的大数乘法都是直接模拟乘法演算过程,复杂度O(n^2),对于这题来说会超时.乘法的过程基本 ...

随机推荐

  1. [Locked] Sparse Matrix Multiplication

    Given two sparse matrices A and B, return the result of AB. You may assume that A's column number is ...

  2. poj2926 曼哈顿最远距离

    题目链接:http://poj.org/problem?id=2926 #include<cstdio> #include<cstring> #include<cmath ...

  3. Scrapy:Python的爬虫框架

    网络爬虫,是在网上进行数据抓取的程序,使用它能够抓取特定网页的HTML数据.虽然我们利用一些库开发一个爬虫程序,但是使用框架可以大大提高效率,缩短开发时间.Scrapy是一个使用Python编写的,轻 ...

  4. Lucene简介

    1 lucene简介1.1 什么是lucene    Lucene是一个全文搜索框架,而不是应用产品.因此它并不像www.baidu.com 或者google Desktop那么拿来就能用,它只是提供 ...

  5. Java GC CMS 日志分析

    https://blogs.oracle.com/poonam/entry/understanding_cms_gc_logs 笔者对其中某几条记录又进行了详细说明,以下是一条完整的CMS日志记录的示 ...

  6. [Ruby] LEVEL 2 Methods and Classes

    Optional Arguments Set default arguments, when we don't need to call it, we can simply skip it. def ...

  7. springMVC3学习(二)--ModelAndView对象

    当控制器处理完请求时,一般会将包括视图名称或视图对象以及一些模型属性的ModelAndView对象返回到DispatcherServlet. 因此,常常须要在控制器中构造ModelAndView对象. ...

  8. 解决java.sql.SQLException: Parameter number X is not an OUT parameter--转

    最近独自一个人写项目,孤军奋战的程序猿可真伤不起! Java 调用MYSQL带输入输出参数存储过程时如题错误:java.sql.SQLException: Parameter number X is ...

  9. Android开发艺术探索》读书笔记 (12) 第12章 Bitmap的加载和Cache

    第12章 Bitmap的加载和Cache 12.1 Bitmap的高速加载 (1)Bitmap是如何加载的?BitmapFactory类提供了四类方法:decodeFile.decodeResourc ...

  10. Android开发系列(一)Activity与Fragment获取屏幕获取屏幕像素的不同方式

    Activity中常用的获取屏幕像素代码: //获取屏幕像素相关信息 DisplayMetrics dm = new DisplayMetrics(); getWindowManager().getD ...