fft模板 HDU 1402
// fft模板 HDU 1402 #include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <math.h>
#include <memory.h>
#include <bits/stdc++.h>
using namespace std;
#define LL long long
typedef pair<int,int> pii;
const LL inf = 0x3f3f3f3f;
const LL MOD =100000000LL;
const int N = ;
const double eps = 1e-;
void fre() {freopen("in.txt","r",stdin);}
void freout() {freopen("out.txt","w",stdout);}
inline int read() {int x=,f=;char ch=getchar();while(ch>''||ch<'') {if(ch=='-') f=-; ch=getchar();}while(ch>=''&&ch<='') {x=x*+ch-'';ch=getchar();}return x*f;} const double PI = acos(-1.0);
//复数结构体
struct Complex{
double r,i;
Complex(double _r = 0.0,double _i = 0.0){
r = _r; i = _i;
}
Complex operator +(const Complex &b){
return Complex(r+b.r,i+b.i);
}
Complex operator -(const Complex &b){
return Complex(r-b.r,i-b.i);
}
Complex operator *(const Complex &b){
return Complex(r*b.r-i*b.i,r*b.i+i*b.r);
}
};
/*
* 进行FFT和IFFT前的反转变换。
* 位置i和 (i二进制反转后位置)互换
* len必须去2的幂
*/
void change(Complex y[],int len){
int i,j,k;
for(i = , j = len/;i < len-; i++){
if(i < j)swap(y[i],y[j]);
//交换互为小标反转的元素,i<j保证交换一次
//i做正常的+1,j左反转类型的+1,始终保持i和j是反转的
k = len/;
while( j >= k){
j -= k;
k /= ;
}
if(j < k) j += k;
}
}
/*
* 做FFT
* len必须为2^k形式,
* on==1时是DFT,on==-1时是IDFT
*/
void fft(Complex y[],int len,int on){
change(y,len);
for(int h = ; h <= len; h <<= ){
Complex wn(cos(-on**PI/h),sin(-on**PI/h));
for(int j = ;j < len;j+=h){
Complex w(,);
for(int k = j;k < j+h/;k++){
Complex u = y[k];
Complex t = w*y[k+h/];
y[k] = u+t;
y[k+h/] = u-t;
w = w*wn;
}
}
}
if(on == -)
for(int i = ;i < len;i++)
y[i].r /= len;
} Complex a[N],b[N];
char s1[N/],s2[N/];
int ans[N];
int main(){
while(~scanf("%s%s",s1,s2)){
int len1=strlen(s1);
int len2=strlen(s2);
int l1=,l2=;
while((<<l1)<len1) l1++;
while((<<l2)<len2) l2++;
int len=(<<(max(l1,l2)+));
for(int i=;i<len;i++){
if(i<len1) a[i]=Complex(s1[len1-i-]-'',);
else a[i]=Complex(,);
if(i<len2) b[i]=Complex(s2[len2-i-]-'',);
else b[i]=Complex(,);
}
fft(a,len,);
fft(b,len,);
for(int i=;i<len;i++)
a[i]=a[i]*b[i];
fft(a,len,-);
for(int i=;i<len;i++)
ans[i]=(int)(a[i].r+0.5);
for(int i=;i<len-;i++){
ans[i+]+=ans[i]/;
ans[i]%=;
}
bool flag=false;
for(int i=len-;i>=;i--){
if(ans[i]) printf("%d",ans[i]),flag=true;
else if(flag||i==)printf("");
}
printf("\n");
}
return ;
}
fft模板 HDU 1402的更多相关文章
- HDU 1402 A * B Problem Plus (FFT模板题)
FFT模板题,求A*B. 用次FFT模板需要注意的是,N应为2的幂次,不然二进制平摊反转置换会出现死循环. 取出结果值时注意精度,要加上eps才能A. #include <cstdio> ...
- HDU 1402 FFT 大数乘法
$A * B$ FFT模板题,找到了一个看起来很清爽的模板 /** @Date : 2017-09-19 22:12:08 * @FileName: HDU 1402 FFT 大整数乘法.cpp * ...
- hdu 1402 A * B Problem Plus FFT
/* hdu 1402 A * B Problem Plus FFT 这是我的第二道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 ...
- hdu1402(大数a*b&fft模板)
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1402 题意: 给出两个长度1e5以内的大数a, b, 输出 a * b. 思路: fft模板 详情参 ...
- 再写FFT模板
没什么好说的,今天又考了FFT(虽然不用FFT也能过)但是确实有忘了怎么写FFT了,于是乎只有重新写一遍FFT模板练一下手了.第一部分普通FFT,第二部分数论FFT,记一下模数2^23*7*17+1 ...
- FFT模板(多项式乘法)
FFT模板(多项式乘法) 标签: FFT 扯淡 一晚上都用来捣鼓这个东西了...... 这里贴一位神犇的博客,我认为讲的比较清楚了.(刚好适合我这种复数都没学的) http://blog.csdn.n ...
- P1919 【模板】A*B Problem升级版 /// FFT模板
题目大意: 给定l,输入两个位数为l的数A B 输出两者的乘积 FFT讲解 这个讲解蛮好的 就是讲解里面贴的模板是错误的 struct cpx { double x,y; cpx(double _x= ...
- [hdu1402]大数乘法(FFT模板)
题意:大数乘法 思路:FFT模板 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 ...
随机推荐
- python pywin32学习笔记
参考博客链接 https://blog.csdn.net/polyhedronx/article/details/81988948 参考博客链接 https://www.cnblogs.com/zha ...
- 「APIO 2019」奇怪装置
题目 考虑推柿子 最开始的想法是如果两个\(t\)在\(mod\ B\)意义下相等,那么只需要比较一下\((t+\left \lfloor \frac{t}{B}\rfloor \right)mod\ ...
- 18-3-bind
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- 在 my_rootfs 中建立 Linux 目录树
[arm@localhost my_rootfs]#mkdir bin dev etc home lib mnt proc sbin sys tmp root usr [arm@localhost m ...
- CSS选择器及优先级
转自CSS优先级的计算公式:http://wyz.67ge.com/css-selector-priority/ 通常我们可以将CSS的优先级由高到低分为六组: 无条件优先的属性只需要在属性后面使用 ...
- matlab之原始处理图像几何变换
(一)图像几何变换理论知识 (1)图像的平移与比例 图像的平移很简单,平移前后的坐标分别为(x,y)和(x',y'),则满足的关系式为 x'= x +Tx: y'= y +Ty: 其中Tx与Ty分别为 ...
- mysql出现ERROR 1366 (HY000):的解决办法
今天向新建的表中添加内容,出现以下错误: mysql> INSERT tdb_goods (goods_name,goods_cate,brand_name,goods_price,is_sho ...
- leetcode-86-分割链表
题目描述: 方法一: # Definition for singly-linked list. # class ListNode: # def __init__(self, x): # self.va ...
- 回首2018 | 分析型数据库AnalyticDB: 不忘初心 砥砺前行
题记 分析型数据库AnalyticDB(下文简称ADB),是阿里巴巴自主研发.唯一经过超大规模以及核心业务验证的PB级实时数据仓库.截止目前,现有外部支撑客户既包括传统的大中型企业和政府机构,也包括众 ...
- pyQT Dialog默认选中某一个选项问题的解决
方法一: 在新建ui文件时不要新建Dialog # -*- coding: utf-8 -*- # Form implementation generated from reading ui file ...