HDU 1402 FFT
来源:互联网 发布:淘宝药店七乐康 假 编辑:程序博客网 时间:2024/06/08 18:04
code :
#include <cstdio>#include <cmath>#include <cstring>using namespace std;typedef double ld;const ld PI = acos(-1.0);const int N = 50010;const int maxN = 150010;char A[maxN], B[maxN];inline int max(int a, int b){return a >= b ? a : b;}struct Complex{/**复数*/ ld real, vir; Complex(){} Complex(ld r, ld v):real(r), vir(v){} Complex operator + (const Complex &rhs) const{ return Complex(real + rhs.real, vir + rhs.vir); } Complex operator - (const Complex &rhs) const{ return Complex(real - rhs.real, vir - rhs.vir); } Complex operator * (const Complex &rhs) const{ return Complex(real * rhs.real - vir * rhs.vir, real * rhs.vir + vir * rhs.real); }}fa[maxN], fb[maxN], tmp[maxN];int ans[maxN];void FFT(Complex t[], int len, int f){/**递归写法*/ if(len == 1) return; //f = -f; Complex wn(cos(2 * PI / len * f), sin(2 * PI / len * f)); for(int i = 0; i < len / 2; ++i) tmp[i] = t[i * 2], tmp[len / 2 + i] = t[i * 2 + 1]; for(int i = 0; i < len; ++i) t[i] = tmp[i]; FFT(t, len / 2, f); FFT(t + len / 2, len / 2, f); Complex w(1, 0); for(int i = 0; i < len / 2; ++i){ Complex u = t[i]; Complex v = w * t[i + len / 2]; t[i] = u + v; t[i + len / 2] = u - v; w = w * wn; }}int main(){ while(~scanf("%s%s", A, B)){ memset(ans, 0, sizeof ans); int lena = strlen(A), lenb = strlen(B); int lent = max(lena, lenb); lent <<= 1; int len = 1; while(len < lent) len <<= 1;/**2的幂*/ // printf("%d\n", len); for(int i = 0; i < len; ++i){ if(i < lena) fa[i] = Complex(A[lena - i - 1] - '0', 0); else fa[i] = Complex(0, 0); if(i < lenb) fb[i] = Complex(B[lenb - i - 1] - '0', 0); else fb[i] = Complex(0, 0); } FFT(fa, len, 1);/**系数到点值*/ FFT(fb, len, 1); for(int i = 0; i < len; ++i) fa[i] = fa[i] * fb[i]; FFT(fa, len, -1); for(int i = 0; i < len; ++i){ fa[i].real /= len; fa[i].vir /= len; }/**点值到系数*/ for(int i = 0; i < len; ++i) ans[i] = (int)(fa[i].real + 0.5); for(int i = 0; i < len; ++i){ ans[i + 1] += ans[i] / 10; ans[i] %= 10; } int id = lena + lenb - 1; while(ans[id] == 0 && id) --id;/**注意0数据*/ for(int i = id; i >= 0; --i) printf("%d", ans[i]); puts(""); } return 0;}
0 0
- hdu 1402 FFT
- HDU 1402 FFT
- HDU 1402 FFT
- FFT 模板(hdu 1402)
- hdu 1402(FFT)
- [FFT] HDU 1402
- HDU 1402 快速傅里叶变换FFT
- hdu 1402 (FFT 模版)
- HDU 1402 大数乘法 FFT
- hdu 1402 FFT(模板)
- HDU 1402 A * B (FFT)
- hdu 1402(FFT+大数乘法)
- HDU 1402 FFT 求 大数乘法
- hdu 1402 A * B Problem Plus FFT
- HDU 1402 A * B Problem Plus FFT
- [HDU 1402]A * B Problem Plus(FFT)
- HDU 1402 A * B Problem Plus FFT
- 【HDU】1402 A * B Problem Plus 【FFT】
- Android5.1 在init.rc 中添加自己的服务
- BZOJ 4542([Hnoi2016]序列-莫队)
- java创建文件夹和删除文件夹
- CentOS安装ElasticSearch极简手册
- Oracle 存储过程的默认值参数和过程中的事务处理
- HDU 1402 FFT
- 装箱P37
- restTemplate Not enough variable values availabel
- LeetCode OJ-513.Find Bottom Left Tree Value
- Swift 中的SDWebImage类似库Kingfisher
- C# 如何读取配置Web.config中的数据
- RTMP集合消息详解
- android studio--调试---断点调试
- Android系统的版本号与API的对应表