hdu 1402 A * B Problem Plus FFT
/*
hdu 1402 A * B Problem Plus FFT 这是我的第二道FFT的题 第一题是完全照着别人的代码敲出来的,也不明白是什么意思 这个代码是在前一题的基础上改的 做完这个题,我才有点儿感觉,原来FFT在这里就是加速大整数乘法而已 像前一题,也是一个大整数乘法,然后去掉一些非法的情况 */
#pragma warning(disable : 4786)
#pragma comment(linker, "/STACK:102400000,102400000")
#include <iostream>
#include <string>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <functional>
#include <map>
#include <set>
#include <vector>
#include <stack>
#include <queue>//priority_queue
#include <bitset>
#include <complex>
#include <utility>
/*
**make_pair()
**/
using namespace std;
const double eps=1e-8;
const double PI=acos(-1.0);
const int inf=0x7fffffff;
template<typename T> inline T MIN(T a,T b){return a<b?a:b;}
template<typename T> inline T MAX(T a,T b){return a>b?a:b;}
template<typename T> inline T SQR(T a){return a*a;}
inline int dbcmp(double a){return a>eps?(1):(a<(-eps)?(-1):0);} typedef __int64 LL;
int n;
const int size=400040;
int data[size/4];
int sum[size];
complex<double> x1[size],num1[size],num2[size]; void change(complex<double> y[],int len)
{
int i,j,k;
for(i = 1, j = len/2;i < len-1;i++)
{
if(i < j)swap(y[i],y[j]);
k = len/2;
while( j >= k)
{
j -= k;
k /= 2;
}
if(j < k)j += k;
}
}
void fft(complex<double> y[],int len,int on)
{
change(y,len);
for(int h = 2;h <= len;h <<= 1)
{
complex<double> wn(cos(-on*2*PI/h),sin(-on*2*PI/h));
for(int j = 0;j < len;j += h)
{
complex<double> w(1,0);
for(int k = j;k < j+h/2;k++)
{
complex<double> u = y[k];
complex<double> t = w*y[k+h/2];
y[k] = u+t;
y[k+h/2] = u-t;
w = w*wn;
}
}
}
if(on == -1)
for(int i = 0;i < len;i++)
y[i].real(y[i].real()/len);
}
char s1[size];
char s2[size];
int main() {
// your code goes here
int t,i,j;
int len,len1,len2;
//cin>>t;
while(gets(s1))
{
gets(s2);
memset(num1,0,sizeof(num1));
memset(num2,0,sizeof(num2));
len1=strlen(s1);
len2=strlen(s2);
//printf("%d %d",len1,len2);
len=1;
while(len<2*len1||len<len2*2) len<<=1;
for(i=len1-1,j=0;i>=0;--i,++j)
{
num1[j]=complex<double>(s1[i]-'0',0);
}
while(j<=len)
{
num1[j]=complex<double>(0,0);
++j;
}
for(i=len2-1,j=0;i>=0;--i,++j)
{
num2[j]=complex<double>(s2[i]-'0',0);
}
while(j<=len)
{
num2[j]=complex<double>(0,0);
++j;
}
fft(num1,len,1);
fft(num2,len,1);
for(i=0;i<len;++i)
{
num1[i]=num1[i]*num2[i];
}
fft(num1,len,-1); for(i=0;i<len;++i)
{
sum[i]=(int)(num1[i].real()+0.5);
}
for(i=0;i<len;++i)
{
sum[i+1]+=sum[i]/10;
sum[i]=sum[i]%10;
}
len=len1+len2-1;
while(sum[len]<=0&&len>0) --len;
for(;len>=0;--len)
{
printf("%c",sum[len]+'0');
}
printf("\n");
}
return 0;
}
hdu 1402 A * B Problem Plus FFT的更多相关文章
- HDU - 1402 A * B Problem Plus FFT裸题
http://acm.hdu.edu.cn/showproblem.php?pid=1402 题意: 求$a*b$ 但是$a$和$b$的范围可以达到 $1e50000$ 题解: 显然...用字符串模拟 ...
- HDU 1402 A * B Problem Plus (FFT求高精度乘法)
A * B Problem Plus Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Other ...
- HDU 1402 A * B Problem Plus (FFT模板题)
FFT模板题,求A*B. 用次FFT模板需要注意的是,N应为2的幂次,不然二进制平摊反转置换会出现死循环. 取出结果值时注意精度,要加上eps才能A. #include <cstdio> ...
- HDU - 1402 A * B Problem Plus (FFT实现高精度乘法)
题意:计算A*B,A,B均为长度小于50000的整数. 这是FFT在大整数相乘中的一个应用,我本来想用NTT做的,但NTT由于取模很可能取炸,所以base必须设得很小,而且效率也比不上FFT. A和B ...
- HDU 1402 A * B Problem Plus 快速傅里叶变换 FFT 多项式
http://acm.hdu.edu.cn/showproblem.php?pid=1402 快速傅里叶变换优化的高精度乘法. https://blog.csdn.net/ggn_2015/artic ...
- hdu 1402 A * B Problem Plus (FFT模板)
A * B Problem Plus Problem Description Calculate A * B. Input Each line will contain two integers A ...
- HDU 1402 A * B Problem Plus(FFT)
Problem Description Calculate A * B. Input Each line will contain two integers A and B. Process to ...
- FFT(快速傅立叶变换):HDU 1402 A * B Problem Plus
Calculate A * B. Input Each line will contain two integers A and B. Process to end of file. Note: th ...
- HDU 1402 A * B Problem Plus ——(大数乘法,FFT)
因为刚学fft,想拿这题练练手,结果WA了个爽= =. 总结几点犯的错误: 1.要注意处理前导零的问题. 2.一定要注意数组大小的问题.(前一个fft的题因为没用到b数组,所以b就没管,这里使用了b数 ...
随机推荐
- js正则表达式中的问号使用技巧总结
这篇文章主要介绍了js正则表达式中的问号几种用法,比如+?,*?,{2,3}?可以停止匹配的贪婪模式等例子的解析. 在表示重复的字符后面加问号,比如+?,*?,{2,3}?可以停止匹配的贪婪模式. v ...
- 配置Ssh免密码登录
配置Ssh免密码登录 一个master节点,两个client节点(client1.client2) 1.所有节点创建hadoop用户,并设置密码 以root账号登录: useradd hadoop p ...
- Topcoder SRM 639 (Div.2)
A.ElectronicPetEasy [题意]一个数st1开始,每次加p1,一共加t1次,另外一个数st2开始,每次加p2,一共加t2次,输入的数均小于1000,问这两个数有没有可能相等,有可能输出 ...
- springMVC如何判断入参是默认参数还是请求传过来的参数?
springMVC如何判断入参是默认参数还是请求传过来的参数?
- querydsl的好处
http://www.querydsl.com/ 封装了很多访问不同数据层平台的方法,提供统一的通用框架(统一的书写格式,以一种通用的API方式来构建查询).便于抽成统一数据层,昨晚底层,以后其他模块 ...
- iOS 网络与多线程--5.异步Post方式的网络请求(非阻塞)
通过Post请求方式,异步获取网络数据,异步请求不会阻塞主线程,而会建立一个新的线程来操作. 代码如下 ViewController.h文件 #import <UIKit/UIKit.h> ...
- 如何安装Git到MAC OS X
这里介绍两种方式:一,使用Git command-line二,使用GUI工具SourceTree,功能很强大,很方便 在进行安装前,要说一下,Git和SVN一样,都需要创建一个服务器的,他们都可以创建 ...
- 读取XML文件的几种方式的效率分析
第一种:使用XmlReader来读取. Stopwatch sw = Stopwatch.StartNew(); List<Dictionary<string, string>> ...
- 编辑一个类库项目 即*.csproj这个文件的正确方式
以前总是用记事本打开,删除一些或增加一些已修改的文件 今天才知道,正确的方式为: 右键单击类库,选择“卸载项目”,然后再右键单击已卸载变为灰色的类库,选择“编辑*.csproj” 编辑完了重新加载一下 ...
- Rand
我看了下网上,是这样的:rand()随机产生一个数(0-65535),加上%后,就是对其它数求余,求余产生的数取决于求余的数.比如,rand()%20;意思是利用rand()的返回值(一个0-6553 ...