【BZOJ2179】FFT快速傅立叶
【BZOJ2179】FFT快速傅立叶
Description
Input
Output
Sample Input
3
4
Sample Output
数据范围:
题解:板子题,敲板子~
#include <cstdio>
#include <cstring>
#include <iostream>
#include <cmath>
#define pi acos(-1.0)
using namespace std;
struct cp
{
double x,y;
cp(double x0,double y0)
{
x=x0,y=y0;
}
cp(){}
cp operator +(const cp a)const
{
return cp(x+a.x,y+a.y);
}
cp operator -(const cp a)const
{
return cp(x-a.x,y-a.y);
}
cp operator *(const cp a)const
{
return cp(x*a.x-y*a.y,x*a.y+y*a.x);
}
}n1[1<<20],n2[1<<20];
int n;
char str[1<<20];
int ans[1<<20];
int rd()
{
int ret=0,f=1; char gc=getchar();
while(gc<'0'||gc>'9') {if(gc=='-')f=-f; gc=getchar();}
while(gc>='0'&&gc<='9') ret=ret*10+gc-'0',gc=getchar();
return ret*f;
}
void init(cp *a,int len)
{
int i,j,t=0;
for(i=0;i<len;i++)
{
if(i>t) swap(a[i],a[t]);
for(j=(len>>1);(t^=j)<j;j>>=1);
}
}
void FFT(cp *a,int len,int f)
{
init(a,len);
int h,i,j,k;
cp t;
for(h=2;h<=len;h<<=1)
{
cp wn(cos(f*2*pi/h),sin(f*2*pi/h));
for(j=0;j<len;j+=h)
{
cp w(1,0);
for(k=j;k<j+h/2;k++) t=w*a[k+h/2],a[k+h/2]=a[k]-t,a[k]=a[k]+t,w=w*wn;
}
}
if(f==-1) for(i=0;i<len;i++) a[i].x=a[i].x/len;
}
void work(cp *a,cp *b,int len)
{
FFT(a,len,1),FFT(b,len,1);
for(int i=0;i<len;i++) a[i]=a[i]*b[i];
FFT(a,len,-1);
for(int i=0;i<len;i++) ans[i]=int(a[i].x+0.1);
}
int main()
{
n=rd();
int i,j,t=0,len=1;
while(len<n*2) len<<=1;
scanf("%s",str);
for(i=0;i<n;i++) n1[n-i-1]=cp(str[i]-'0',0);
scanf("%s",str);
for(i=0;i<n;i++) n2[n-i-1]=cp(str[i]-'0',0);
for(i=n;i<len;i++) n1[i]=n2[i]=cp(0,0);
work(n1,n2,len);
len=2*n-1;
for(i=0;i<=len;i++) ans[i+1]+=ans[i]/10,ans[i]%=10;
while(ans[len]<=0&&len) len--;
for(i=len;i>=0;i--) printf("%d",ans[i]);
return 0;
}
【BZOJ2179】FFT快速傅立叶的更多相关文章
- [bzoj2179]FFT快速傅立叶_FFT
FFT快速傅立叶 bzoj-2179 题目大意:给出两个n位10进制整数x和y,你需要计算x*y. 注释:$1\le n\le 6\times 10^4$. 想法: $FFT$入门题. $FFT$实现 ...
- BZOJ2179: FFT快速傅立叶 & caioj1450:【快速傅里叶变换】大整数乘法
[传送门:BZOJ2179&caioj1450] 简要题意: 给出两个超级大的整数,求出a*b 题解: Rose_max出的一道FFT例题,卡掉高精度 = =(没想到BZOJ也有) 只要把a和 ...
- bzoj2179: FFT快速傅立叶
#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> ...
- bzoj千题计划166:bzoj2179: FFT快速傅立叶
http://www.lydsy.com/JudgeOnline/problem.php?id=2179 FFT做高精乘 #include<cmath> #include<cstdi ...
- BZOJ2179:FFT快速傅立叶(FFT)
Description 给出两个n位10进制整数x和y,你需要计算x*y. Input 第一行一个正整数n. 第二行描述一个位数为n的正整数x. 第三行描述一个位数为n的正整数y. Output 输出 ...
- BZOJ2179: FFT快速傅立叶 FFT实现高精度乘法
Code: #include <cstdio> #include <algorithm> #include <cmath> #include <cstring ...
- 【bzoj2179】FFT快速傅立叶 FFT模板
2016-06-01 09:34:54 很久很久很久以前写的了... 今天又比较了一下效率,貌似手写复数要快很多. 贴一下模板: #include<iostream> #include& ...
- BZOJ 2179: FFT快速傅立叶
2179: FFT快速傅立叶 Time Limit: 10 Sec Memory Limit: 259 MBSubmit: 2923 Solved: 1498[Submit][Status][Di ...
- 【BZOJ 2179】 2179: FFT快速傅立叶 (FFT)
2179: FFT快速傅立叶 Time Limit: 10 Sec Memory Limit: 259 MBSubmit: 3308 Solved: 1720 Description 给出两个n位 ...
随机推荐
- crc32 根据字符串获取校验值
using System;using System.Collections.Generic;using System.IO;using System.Linq;using System.Text; n ...
- js+CSS 实现可以编辑的下拉列表框
<html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="C ...
- php安全处理
1.php.ini 修改 open_basedir='d:\wwwroot' //配置只能访问指定的网站目录 2.php.ini 修改 disable_funcitons=system,passthr ...
- C# DateTime 时间格式
//2008年4月24日 System.DateTime.Now.ToString("D"); //2008-4-24 System.DateTime.Now.ToString(& ...
- 新型I/O架构引领存储之变(二)
新型I/O架构引领存储之变(二) 作者:廖恒 众所周知,支持存储及网络I/O服务的接口协议有很多种.比方,以太网及Infiniband接口都支持採用iSCSI协议来实现存储业务,它们也因而成为了ser ...
- 【Android】利用Fiddler进行抓包详解教程。抓取接口以及数据,可以抓真实安卓手机或者模拟器。
大家都知道抓包的方法很多.我这里给大家介绍介绍一种,利用fiddler进行抓包,当然比如Wireshark也可以抓包,我们这里不做介绍.我这里演示的是fiddler+天天模拟器,当然真实安卓手机也是一 ...
- struts解决form提交的中文参数乱码问题
根据struts的工作原理,原文摘自<Java Web 开发实战经典> 在运行一个JSP页面前,会调用指定的ActionForm中的reset()方法,进行表单元素的初始化 因此,在相应的 ...
- python学习笔记1--python简介
Python翻译中文是蟒蛇.发明人guido喜欢蟒蛇马戏团,故起名python. python发展简史: --CNRI时期.CNRI资助Python发展的重要单位,python1.5版之前的成果大部分 ...
- 使用command对象添加删除查询记录
private void button1_Click(object sender, EventArgs e) { //实例化数据库连接对象 SqlConnection sqlcon = new Sql ...
- IPC之共享内存
man 7 shm_overview shm_overview - Overview of POSIX shared memory. 同样,SystemV实现的共享内存是旧的机制,但应用广泛:Posi ...