#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;
const double PI=acos(-);
const int maxn=;
int n,len,m,rev[maxn],ans[maxn];
struct node{
double real,imag;
node operator +(const node &x){return (node){real+x.real,imag+x.imag};}
node operator -(const node &x){return (node){real-x.real,imag-x.imag};}
node operator *(const node &x){return (node){real*x.real-imag*x.imag,real*x.imag+imag*x.real};}
}a[maxn],b[maxn],c[maxn],w,wn,t1,t2;
void read(int &x){
x=; int f=; char ch;
for (ch=getchar();!isdigit(ch);ch=getchar()) if (ch=='-') f=-;
for (;isdigit(ch);ch=getchar()) x=x*+ch-''; x*=f;
}
void Read(node *a){
char ch;
for (int i=m-;i>=;i--){
for (ch=getchar();!isdigit(ch);ch=getchar());
a[i].real=(double)(ch-'');
}
}
int Rev(int x){
int temp=;
for (int i=;i<len;i++) temp<<=,temp+=(x&),x>>=;
return temp;
}
void FFT(node *a,int op){
for (int i=;i<n;i++) if (i<rev[i]) swap(a[i],a[rev[i]]);
for (int s=;s<=n;s<<=){
wn=(node){cos(op**PI/s),sin(op**PI/s)};
for (int i=;i<n;i+=s){
w=(node){,};
for (int j=i;j<i+s/;j++,w=w*wn){
t1=a[j],t2=w*a[j+s/];
a[j]=t1+t2,a[j+s/]=t1-t2;
}
}
}
}
int main(){
read(m); n=,len=;
while (n<(m<<)) n<<=,len++;
Read(a),Read(b);
for (int i=;i<n;i++) rev[i]=Rev(i);
FFT(a,),FFT(b,);
for (int i=;i<n;i++) c[i]=a[i]*b[i];
FFT(c,-);
for (int i=;i<n;i++) ans[i]=(int)round(c[i].real/n);
for (int i=;i<n;i++) ans[i+]+=ans[i]/,ans[i]=ans[i]%;
int j; for (j=n-;j>=;j--) if (ans[j]) break;
if (j==-) puts("");
else{for (;j>=;j--) printf("%d",ans[j]);puts("");}
return ;
}

题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=2179

题目大意:给定两个大数a,b,求a*b,位数n<=60000;

做法:FFT入门题,FFT的做法可以自己去看算法导论,这题是裸的卷积,直接上DFT或者NTT,我贴的是DFT的。

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

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

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

  2. BZOJ2179: FFT快速傅立叶 & caioj1450:【快速傅里叶变换】大整数乘法

    [传送门:BZOJ2179&caioj1450] 简要题意: 给出两个超级大的整数,求出a*b 题解: Rose_max出的一道FFT例题,卡掉高精度 = =(没想到BZOJ也有) 只要把a和 ...

  3. bzoj千题计划166:bzoj2179: FFT快速傅立叶

    http://www.lydsy.com/JudgeOnline/problem.php?id=2179 FFT做高精乘 #include<cmath> #include<cstdi ...

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

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

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

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

  6. 【BZOJ2179】FFT快速傅立叶

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

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

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

  8. BZOJ 2179: FFT快速傅立叶

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

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

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

随机推荐

  1. Android中asset和raw的区别

    :assets 文件夹是存放不进行编译加工的原生文件,即该文件夹里面的文件不会像 xml, java 文件被预编译,可以存放一些图片,html,js, css 等文件.

  2. Invoke--转载

    在多线程编程中,我们经常要在工作线程中去更新界面显示,而在多线程中直接调用界面控件的方法是错误的做法,Invoke 和 BeginInvoke 就是为了解决这个问题而出现的,使你在多线程中安全的更新界 ...

  3. 【转】理解Java Integer的缓存策略

    本文将介绍 Java 中 Integer 缓存的相关知识.这是 Java 5 中引入的一个有助于节省内存.提高性能的特性.首先看一个使用 Integer 的示例代码,展示了 Integer 的缓存行为 ...

  4. linux yum 工具

    vim /etc/yum.repos.d/CentOS-Base.repo 编辑yum 源网址 yum list |grep vim查看vim 情况 yum remove 卸载rpm包 # yum u ...

  5. Eclipse 安装 jBPM 插件

    下载jbpm-installer安装包并解压,找到 jbpm-installer\build.properties搜索eclipse.home 修改 eclipse.home=./eclipse 成 ...

  6. WinRAR的命令行模式用法介绍

    因工作中要对数据打包,顺便研究了下WinRAR的命令行模式,自己写了些例子,基本用法如下: 测试压缩文件准备:文件夹test_data,内部包含子文件夹,分别存放了一些*.log和*.txt文件. 测 ...

  7. Android开发资源汇总

    搜索 虫部落快搜(已被墙) Google免FQ镜像汇总 Lantern stackoverflow 博客 Android基础&进阶 深入理解Android 老罗的Android之旅 Andro ...

  8. BZOJ 2038: [2009国家集训队]小Z的袜子(hose) [莫队算法]【学习笔记】

    2038: [2009国家集训队]小Z的袜子(hose) Time Limit: 20 Sec  Memory Limit: 259 MBSubmit: 7687  Solved: 3516[Subm ...

  9. 数字图像处理中的4邻接,8邻接与m邻接

    像素之间的邻接性: 4邻接.如果q在集合N4(p)中,则具有V中数值的两个像素p和q是4邻接的. 8邻接.如果q在集合N8(p)中,则具有V中数值的两个像素p和q是8邻接的. m邻接(混合邻接).如果 ...

  10. spring mvc+ spring +mybatis

    首先,修改web.xml,添加配置文件路由以及格式过滤 <?xml version="1.0" encoding="UTF-8"?> <web ...