#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. IOS 图片上传处理 图片压缩 图片处理

    - (void)initActionSheet { UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:nil dele ...

  2. Replication-Replication Distribution Subsystem: agent xxxxxx failed. Column names in each table must be unique

    最近遇到一个关于发布订阅(Replication)的奇葩问题,特此记录一下这个案例.我们一SQL SERVER数据库服务器出现大量告警.告警信息如下所示: DESCRIPTION: Replicati ...

  3. winform(三)——更换主窗体例子

    做一个登录窗口,登录成功时关闭form1,展示from2界面 1.主界面Login namespace WindowsFormsApplication1 { public partial class ...

  4. HDFS开发实例

    1.列出HDFS中的文件 package com.hdfs.test; import java.io.BufferedReader; import java.io.IOException; impor ...

  5. Android上传文件至服务器(上)

    每一次都不能上首页,真悲催..管理员让我上一次首页? 很多时候我更愿意一个人写代码,与其在垃圾代码上改改改,我更愿意直接重构. 整洁的代码简单直接.整洁的代码如同优美的散文.整洁的代码从不隐藏设计者的 ...

  6. angularJS操作键值对象(类似java的hashmap)填坑小结

    前言: 我们知道java的hashmap中使用最多的是put(...),get(...)以及remove()方法,那么在angularJS中如何创造(使用)这样一个对象呢 思路分析: 我们知道在jav ...

  7. MySQL性能优化——索引

    原文地址:http://blog.codinglabs.org/articles/theory-of-mysql-index.html InnoDB使用B+Tree作为索引结构 最左前缀原理与相关优化 ...

  8. ubuntu下安装lrzsz

    secureCRT中可以使用rz和sz命令上传和下载文件,可是这要linux中安装了lrzsz才可以.我用的时候无法使用apt-get自动安装,下面介绍手动安装的方法. 1 下载lrzsz软件  ht ...

  9. Qt 之 入门例程 (一)

    以 “Hello Qt” 为例,介绍如何建立一个 Qt 工程 . 1  QLabel 例程 QLabel 继承自 QFrame (继承自 QWidget),主要用来显示文本和图片. 1.1  Hell ...

  10. winform记事本(基本功能)

    本题主要考察各种控件的应用 using System; using System.Collections.Generic; using System.ComponentModel; using Sys ...