2016-06-01  09:34:54

很久很久很久以前写的了。。。

今天又比较了一下效率,貌似手写复数要快很多。

贴一下模板:

 #include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#include<complex>
#define ll long long
#define N 500020
using namespace std;
int read(){
int x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
struct CD{
double a,b;
CD(double x=,double y=){a=x;b=y;}
friend CD operator +(CD n1,CD n2){return CD(n1.a+n2.a,n1.b+n2.b);}
friend CD operator -(CD n1,CD n2){return CD(n1.a-n2.a,n1.b-n2.b);}
friend CD operator *(CD n1,CD n2){return CD(n1.a*n2.a-n1.b*n2.b,n1.a*n2.b+n1.b*n2.a);}
};
int n,m,bit=;
const long double Pi=acos(-1.0); void FFT(CD *a,int n,int type){
for(int i=,j=;i<n;i++) {
if(j>i)swap(a[i],a[j]);
int k=n;
while(j&(k >>= ))j&=~k;
j|=k;
}
for(int i=;i<=bit;i++){
CD w_n(cos(*type*Pi/(<<i)),sin(*type*Pi/(<<i)));
for(int j=;j<(<<bit);j+=(<<i)){
CD w(,);
for(int k=j;k<j+(<<(i-));k++){
CD tmp=a[k],tt=w*a[k+(<<(i-))];
a[k]=a[k]+tt;
a[k+(<<(i-))]=tmp-tt;
w=w*w_n;
}
}
}
if(type<) for(int i=;i<(<<bit);i++) a[i].a=(a[i].a+0.5)/(<<bit);
} CD poly1[N],poly2[N];
int c[N*]; char ch[N];
int main (){
n=read();
scanf("%s",ch+);
for(int i=;i<n;i++)poly1[i]=(double)(ch[n-i]-'');
scanf("%s",ch+);
for(int i=;i<n;i++)poly2[i]=(double)(ch[n-i]-'');
bit=;
while(<<bit<(n<<))bit++;
n=<<bit;
FFT(poly1,n,);FFT(poly2,n,);
for(int i=;i<n;i++)poly1[i]=poly1[i]*poly2[i];
FFT(poly1,n,-);
int jin=,top=;
for(int i=;i<n;i++){
jin+=(int)(poly1[i].a+0.5);
c[++top]=jin%;
jin/=;
}
while(top&&c[top]==) top--;
while(top)putchar(c[top--]+'');
return ;
}

2179: FFT快速傅立叶

Time Limit: 10 Sec  Memory Limit: 259 MB
Submit: 2552  Solved: 1299
[Submit][Status][Discuss]

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

【bzoj2179】FFT快速傅立叶 FFT模板的更多相关文章

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

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

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

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

  3. BZOJ2179:FFT快速傅立叶(FFT)

    Description 给出两个n位10进制整数x和y,你需要计算x*y. Input 第一行一个正整数n. 第二行描述一个位数为n的正整数x. 第三行描述一个位数为n的正整数y. Output 输出 ...

  4. spoj VFMUL FFT快速傅立叶变换模板题

    题意:求两个数相乘. 第一次写非递归的fft,因为一个数组开小了调了两天TAT. #include<iostream> #include<cstring> #include&l ...

  5. 【bzoj2179】FFT快速傅立叶 FFT

    题目描述 给出两个n位10进制整数x和y,你需要计算x*y. 输入 第一行一个正整数n. 第二行描述一个位数为n的正整数x. 第三行描述一个位数为n的正整数y. 输出 输出一行,即x*y的结果. 样例 ...

  6. BZOJ2179: FFT快速傅立叶 FFT实现高精度乘法

    Code: #include <cstdio> #include <algorithm> #include <cmath> #include <cstring ...

  7. BZOJ 2179 FFT快速傅立叶 ——FFT

    [题目分析] 快速傅里叶变换用于高精度乘法. 其实本质就是循环卷积的计算,也就是多项式的乘法. 两次蝴蝶变换. 二进制取反化递归为迭代. 单位根的巧妙取值,是的复杂度成为了nlogn 范德蒙矩阵计算逆 ...

  8. bzoj 2179 FFT快速傅立叶 —— FFT

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=2179 默写板子,注释的是忘记的地方. 代码如下: #include<iostream& ...

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

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

随机推荐

  1. 【PHP小项目使用MVC架构】

    小项目名称是雇员管理系统. mvc是一种项目的开发模式,中文名称为模式视图控制器,是强制程序员将数据的输入.处理.输出分开的一种开发模式. 在这个小项目中,控制器使用service作为后缀名. 项目u ...

  2. HDU3364 Lanterns(求矩阵的秩)

    求矩阵的秩,及判断有无解 #include<cstdio> #include<iostream> #include<cstdlib> #include<cst ...

  3. Oracle buffer cache

    Buffer Cache buffer cache 结构图 HASH链 ORACLE使用HASH算法,把buffer cache中每个buffer的buffer header串联起来,组成多条hash ...

  4. RTP/RTCP的时间同步机制

    转自:http://blog.csdn.net/leesphone/article/details/5571972 RTP支持传送不同codec的steaming,不同codec的clock rate ...

  5. Flash Media Server 4.0 破解 注册

    Adobe Flash Media Interactive Server 3.5s/n:1373-5047-2985-0514-5175-0098 s/n: 1373-5632-4666-9521-8 ...

  6. Linux学习笔记(8)Linux常用命令之网络命令

    (1)write write命令用于给指定用户发信息,以Ctrl+D保存结束,所在路径为/usr/bin/write,其语法格式为: write [用户名] 注:只能给在线用户发送. 例:新建ws用户 ...

  7. Spring官网改版后下载

    Spring官网改版后找了好久都没有找到直接下载Jar包的链接,下面汇总些网上提供的方法,亲测可用. 1.直接输入地址,改相应版本即可:http://repo.springsource.org/lib ...

  8. Android开发中Handler的经典总结

    当应用程序启动时,Android首先会开启一个主线程(也就是UI线程),主线程为管理界面中的UI控件,进行事件分发. AD: 一.Handler的定义: 主要接受子线程发送的数据, 并用此数据配合主线 ...

  9. android中随着ScrollView的滑动,titleBar状态的改变

    今天项目有一个需求,,类是于QQ空间里面的一个功能,于是就研究了一下,嗯,说这么多,可能还有人不知道指的是那个,直接上效果图.见谅,不会弄动态图:   对,就是这种效果,我研究了一下,思路如下: 1. ...

  10. x264源代码 概述 框架分析 架构分析

    函数背景色 函数在图中以方框的形式表现出来.不同的背景色标志了该函数不同的作用: 白色背景的函数:不加区分的普通内部函数. 浅红背景的函数:libx264类库的接口函数(API). 粉红色背景函数:滤 ...