Hdu 1402 (FFT)
A * B Problem Plus
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 12490 Accepted Submission(s): 2206Problem DescriptionCalculate A * B.InputEach line will contain two integers A and B. Process to end of file.Note: the length of each integer will not exceed 50000.
OutputFor each case, output A * B in one line.Sample Input1
2
1000
2Sample Output2
2000
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <queue>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstring>
#include <cctype>
#include <cassert>
#include <limits>
#include <bitset>
#include <complex>
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
#define all(o) (o).begin(), (o).end()
#define rall(o) (o).rbegin(), ((o).rend())
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset(m,v,sizeof(m))
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
using namespace std;
typedef vector<int> vi; typedef pair<int,int> pii; typedef vector<pair<int,int> > vpii;
typedef long long ll; typedef vector<long long> vl; typedef pair<long long,long long> pll; typedef vector<pair<long long,long long> > vpll;
typedef vector<string> vs; typedef long double ld;
template<typename T, typename U> inline void amin(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> inline void amax(T &x, U y) { if(x < y) x = y; } typedef long double Num; //??????long double?????
const Num PI = .141592653589793238462643383279L;
typedef complex<Num> Complex;
//n?????
//a?????
void fft_main(int n, Num theta, Complex a[]) {
for(int m = n; m >= ; m >>= ) {
int mh = m >> ;
Complex thetaI = Complex(, theta);
rep(i, mh) {
Complex w = exp((Num)i*thetaI);
for(int j = i; j < n; j += m) {
int k = j + mh;
Complex x = a[j] - a[k];
a[j] += a[k];
a[k] = w * x;
}
}
theta *= ;
}
int i = ;
reu(j, , n-) {
for(int k = n >> ; k > (i ^= k); k >>= ) ;
if(j < i) swap(a[i], a[j]);
}
} void fft(int n, Complex a[]) { fft_main(n, * PI / n, a); }
void inverse_fft(int n, Complex a[]) { fft_main(n, - * PI / n, a); } void convolution(vector<Complex> &v, vector<Complex> &w) {
int n = , vwn = v.size() + w.size() - ;
while(n < vwn) n <<= ;
v.resize(n), w.resize(n);
fft(n, &v[]);
fft(n, &w[]);
rep(i, n) v[i] *= w[i];
inverse_fft(n, &v[]);
rep(i, n) v[i] /= n;
} const int maxn = ;
vector<int> ans;
char s1[maxn], s2[maxn]; void solve(vector<int> &res) {
//cerr << s1 << s2;
int len1 = strlen(s1), len2 = strlen(s2);
for (int i = ; i < len1; i++) s1[i] -= '';
for (int i = ; i < len2; i++) s2[i] -= '';
vector<Complex> Lc(len1), Rc(len2);
for (int i = ; i < len1; i++) Lc[i] = Complex(s1[len1-i-], );
for (int i = ; i < len2; i++) Rc[i] = Complex(s2[len2-i-], );
convolution(Lc, Rc);
int n = len1 + len2 - ;
res.resize(n);
rep(i, n) res[i] = Lc[i].real() + .;
} int main(void) {
while (~scanf("%s %s", s1, s2)) {
solve(ans);
ans.resize(ans.size() << );
for (int i = ; i < ans.size(); i++) {
ans[i+] += ans[i] / ;
ans[i] %= ;
}
int high = ans.size() - ;
while (high > && !ans[high]) high--;
for (int i = high; i >= ; i--) putchar(ans[i] + '');
putchar('\n');
}
return ;
}
Hdu 1402 (FFT)的更多相关文章
- A * B Problem Plus HDU - 1402 (FFT)
A * B Problem Plus HDU - 1402 (FFT) Calculate A * B. InputEach line will contain two integers A and ...
- hdu 1402(FFT乘法 || NTT乘法)
A * B Problem Plus Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Other ...
- 快速傅里叶(FFT)的快速深度思考
关于按时间抽取快速傅里叶(FFT)的快速理论深度思考 对于FFT基本理论参考维基百科或百度百科. 首先谈谈FFT的快速何来?大家都知道FFT是对DFT的改进变换而来,那么它究竟怎样改进,它改进的思想在 ...
- 【BZOJ3527】力(FFT)
[BZOJ3527]力(FFT) 题面 Description 给出n个数qi,给出Fj的定义如下: \[Fj=\sum_{i<j}\frac{q_i q_j}{(i-j)^2 }-\sum_{ ...
- 【BZOJ4827】【HNOI2017】礼物(FFT)
[BZOJ4827][HNOI2017]礼物(FFT) 题面 Description 我的室友最近喜欢上了一个可爱的小女生.马上就要到她的生日了,他决定买一对情侣手 环,一个留给自己,一 个送给她.每 ...
- FFT/NTT总结+洛谷P3803 【模板】多项式乘法(FFT)(FFT/NTT)
前言 众所周知,这两个东西都是用来算多项式乘法的. 对于这种常人思维难以理解的东西,就少些理解,多背板子吧! 因此只总结一下思路和代码,什么概念和推式子就靠巨佬们吧 推荐自为风月马前卒巨佬的概念和定理 ...
- 【BZOJ4503】两个串(FFT)
[BZOJ4503]两个串(FFT) 题面 给定串\(S\),以及带通配符的串\(T\),询问\(T\)在\(S\)中出现了几次.并且输出对应的位置. \(|S|,|T|<=10^5\),字符集 ...
- 【BZOJ4259】残缺的字符串(FFT)
[BZOJ4259]残缺的字符串(FFT) 题面 给定两个字符串\(|S|,|T|\),两个字符串中都带有通配符. 回答\(T\)在\(S\)中出现的次数. \(|T|,|S|<=300000\ ...
- 【51Nod1258】序列求和V4(FFT)
[51Nod1258]序列求和V4(FFT) 题面 51Nod 多组数据,求: \[Ans=\sum_{i=1}^ni^k,n\le 10^{18},k\le50000\] 题解 预处理伯努利数,时间 ...
随机推荐
- Django问题2
接触django是从上个月开始,学习python时间也不长,但我经常在社区看看别人发表的文章,早上看到一篇不错的博客,却一直不能访 问,最终从bing的缓存里找到,因为害怕丢失和忘掉,所以顺便翻译过来 ...
- 【BZOJ4805】欧拉函数求和
题面 Description 给出一个数字N,求\(\sum\limits_{i=1}^n\varphi(i)\)i,1<=i<=N Input 正整数N.N<=2*10^9 Out ...
- CSS3 学习笔记(动画 多媒体查询)
动画 1.@keyframes规则用于创建动画.在@keyframes中规定某项CSS样式,就能创建由当前样式逐渐改为新样式的动画效果 2.使用animation进行动画捆绑.两个值:动画名称.时长 ...
- PHP函数高级(二)
PHP函数基础:https://www.cnblogs.com/lxwphp/p/9867840.html 1.函数分类: 定义:完成某些功能的代码段 系统函数:字符串,数组,数字,日期时间 自定 ...
- Windows的SEH机理简要介绍
1.异常分类 一般来说,我们把Exception分为2类,一类是CPU产生的异常,我们称之为CPU异常(或者硬件异常).另一类为是通过调用RaiseException API产生的软件异常,我们称之为 ...
- PAT甲级——A1091 Acute Stroke【30】
One important factor to identify acute stroke (急性脑卒中) is the volume of the stroke core. Given the re ...
- Cocos2d-x发布Android.mk 导入所有cpp
#traverse all the directory and subdirectorydefine walk $(wildcard $(1)) $(foreach e, $(wildcard $(1 ...
- 使用Colaboratory的免费GPU训练神经网络
1 Colaboratory 介绍 Colaboratory 是一个 Google 研究项目,旨在帮助传播机器学习培训和研究成果.它是一个 Jupyter 笔记本环境,不需要进行任何设置就可以使用,并 ...
- 【机器学习】机器学习入门01 - kNN算法
0. 写在前面 近日加入了一个机器学习的学习小组,每周按照学习计划学习一个机器学习的小专题.笔者恰好近来计划深入学习Python,刚刚熟悉了其基本的语法知识(主要是与C系语言的差别),决定以此作为对P ...
- XStream JavaBean对象转换成XML!
代码实例: 1.javaBean类: package com.hsinfo.web.Demo.XStream; public class City { private String name; pub ...