题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1402 一般的的大数乘法都是直接模拟乘法演算过程,复杂度O(n^2),对于这题来说会超时.乘法的过程基本就是等同于多项式相乘的过程,只是没有进位而已.对于这种问题我们需要转化然后用FFT求解.FFT是用来计算离散傅里叶变化(DFT)及其逆变换(IDFT)的快速算法,复杂度O(n*logn).DFT有一个很重要的性质:时域卷积,频域乘积:频域乘积,时域卷积.那么什么是时域.频域.卷积.乘积呢?时域和频域…
Calculate A * B. Input Each line will contain two integers A and B. Process to end of file. Note: the length of each integer will not exceed . Output For each case, output A * B in one line. Sample Input Sample Output 把每一位看成ai*10^i,然后就是两个多项式相乘.利用FFT,…
分析:网上别家的代码都分析的很好,我只是给我自己贴个代码,我是kuangbin的搬运工 一点想法:其实FFT就是快速求卷积罢了,当小数据的时候我们完全可以用母函数来做,比如那种硬币问题 FFT只是用来解决数据规模较大时的办法,可以达到nlogn的效率,大体原理就是运用了n次单位复根的折半引理 具体可以看算法导论 高度仰慕kuangbin大神的模板,实在是不想自己写 对于这个题,我们10^k的系数看成多项式系数,然后求卷积,进位就好了 #include <stdio.h> #include &l…
解题关键:快速傅里叶变换fft练习. 关于结果多项式长度的确定,首先将短多项式扩展为长多项式,然后扩展为两倍. #include<cstdio> #include<cstring> #include<algorithm> #include<cstdlib> #include<iostream> #include<cmath> #include<complex> #define N 131072 #define pi aco…
A * B Problem Plus Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 9413    Accepted Submission(s): 1468 Problem Description Calculate A * B.   Input Each line will contain two integers A and B.…
题意:计算A*B,A,B均为长度小于50000的整数. 这是FFT在大整数相乘中的一个应用,我本来想用NTT做的,但NTT由于取模很可能取炸,所以base必须设得很小,而且效率也比不上FFT. A和B的存储均用long long,在计算乘积的时候转化成double,计算完成后再转回来即可. 测得base在精度允许范围内最多能开到10000. 把平方和快速幂的函数也写上了,可以当模板用~ #include<bits/stdc++.h> using namespace std; typedef l…
#include <iostream> #include <stdio.h> #include <cmath> #include <algorithm> #include <cstring> #include <vector> using namespace std; #define N 50500*2 const double PI = acos(-1.0); struct Vir { double re, im; Vir(., .…
题意:大数乘法 思路: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 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81…
题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=1402 hdu_1402:A * B Problem Plus Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 15419    Accepted Submission(s): 3047 Problem Description Calculat…
/* hdu 1402 A * B Problem Plus FFT 这是我的第二道FFT的题 第一题是完全照着别人的代码敲出来的,也不明白是什么意思 这个代码是在前一题的基础上改的 做完这个题,我才有点儿感觉,原来FFT在这里就是加速大整数乘法而已 像前一题,也是一个大整数乘法,然后去掉一些非法的情况 */ #pragma warning(disable : 4786) #pragma comment(linker, "/STACK:102400000,102400000") #in…