HDU 1402(A * B Problem Plus-FFT速度測試)
A * B Problem Plus
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 15111 Accepted Submission(s): 2942
Problem Description 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 50000.
Output For each case, output A * B in one line.
Sample Input 1 2 1000 2
Sample Output 2 2000
Author DOOM III
Recommend DOOM III | We have carefully selected several similar problems for you:
#include<bits/stdc++.h> using namespace std; #define For(i,n) for(int i=1;i<=n;i++) #define Fork(i,k,n) for(int i=k;i<=n;i++) #define Rep(i,n) for(int i=0;i<n;i++) #define ForD(i,n) for(int i=n;i;i--) #define ForkD(i,k,n) for(int i=n;i>=k;i--) #define RepD(i,n) for(int i=n;i>=0;i--) #define Forp(x) for(int p=pre[x];p;p=next[p]) #define Forpiter(x) for(int &p=iter[x];p;p=next[p]) #define Lson (o<<1) #define Rson ((o<<1)+1) #define MEM(a) memset(a,0,sizeof(a)); #define MEMI(a) memset(a,127,sizeof(a)); #define MEMi(a) memset(a,128,sizeof(a)); #define INF (2139062143) #define F (100000007) #define pb push_back #define mp make_pair #define eps (1e-1) #define MAXN (200000+10) #define pi ((double)3.1415926535897932384626) typedef long long ll; typedef complex<double> cd; class fft { public: cd A[MAXN]; int n,l; void brc(cd *A,int l) { int i,j,k; for(i=1,j=l>>1;i<l-1;i++) { if (i<j) swap(A[i],A[j]); k=l>>1; while(j>=k) { j-=k; k>>=1; } j+=k; } } void DFT(int l,int on) //on { brc(A,l); for(int h=2;h<=l;h<<=1) { cd wn=cd(cos(on*2*pi/h),sin(on*2*pi/h)); for(int j=0;j<l;j+=h) { cd w=cd(1,0); for(int k=j;k<j+h/2;k++) { cd u=A[k],t=w*A[k+h/2]; A[k]=u+t; A[k+h/2]=u-t; w*=wn; } } } if (on==-1) Rep(i,l) A[i]/=l; //DFT = 逆矩陣=-A/l } void mem(int _n) { MEM(A) n=_n; l=1; while(l<n) l<<=1; l<<=1; } void scan(char *a,int n) { MEM(A) Rep(i,n) { A[i]=cd(a[n-i-1]-'0',0); } } }S1,S2; char s1[MAXN],s2[MAXN]; int ans[MAXN]; int main() { // freopen("hdu1402.in","r",stdin); // freopen(".out","w",stdout); while(scanf("%s%s",s1,s2)==2) { int n=strlen(s1),m=strlen(s2); int N=max(n,m); S1.mem(N),S2.mem(N); S1.scan(s1,n); S2.scan(s2,m); S1.DFT(S1.l,1); S2.DFT(S2.l,1); Rep(i,S1.l) S1.A[i]*=S2.A[i]; S1.DFT(S1.l,-1); MEM(ans) Rep(i,S1.l) { ans[i]+=(int)(S1.A[i].real()+0.1); ans[i+1]+=ans[i]/10; ans[i]%=10; } int L=S1.l; while(L&&!ans[L]) --L; RepD (i,L) printf("%d",ans[i]); putchar('\n'); } return 0; }
相關推薦
HDU 1402(A * B Problem Plus-FFT速度測試)
A * B Problem Plus Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 15111 Acc
HDU 1402 A * B Problem Plus FFT
contain linker pri span stack pragma mod exce problem A * B Problem Plus Problem Description Calculate A * B. Input Each line
HDU - 1402 A * B Problem Plus FFT裸題
swa complex asn 直線 lse () strlen mod -i http://acm.hdu.edu.cn/showproblem.php?pid=1402 題意: 求$a*b$ 但是$a$和$b$的範圍可以達到 $1e50000$ 題解: 顯然..
HDU 1402 A * B Problem Plus ( FFT )
amp hid sin 兩個 close 形式 hide utc closed 題意 : 求兩個大數相乘的結果 分析 : 可以將數拆成多項式的形式 例如 12345 (1 * x^4) + (2 * x^3) + (3 * x^2) + (4 * x^1) + (5 *
HDU 1402 A * B Problem Plus(FFT實現高精度乘法)
題意:50000位以內的高精度乘法。 思路:熟悉一下FFT的用法。多項式的乘法實際上是多項式係數向量的卷積,利用FFT進行多項式乘法,步驟如下: 1.補零:在兩個多項式的最前面補零,得到兩個2n次的多項式,設係數向量分別為v1,v2。 2.求值:用FFT計算f1 = DFT
HDU 1402 A * B Problem Plus ——(大數乘法,FFT)
兩個 ret 處理 complex truct std spa strlen mes 因為剛學fft,想拿這題練練手,結果WA了個爽= =。 總結幾點犯的錯誤: 1.要註意處理前導零的問題。 2.一定要註意數組大小的問題。(前一個fft的題因為沒用到b數組,
hdu1402 A * B Problem Plus (FFT)
思路:考慮變成係數的形式,顯然就是兩個的多項式乘法,然後轉化成FFT,直接莽一波就完了。 #include<cstdio> #include<cmath> #include<cstring> #include<algorithm&
hdu 1000 A + B Problem
esc urn rip end ostream accep others cstring line A + B Problem Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Ja
HDU-1000 A + B Problem
amp ostream case ace sam script pre code blog 題目 Problem Description Calculate A + B. Input Each line will contain two integers A and
A*B problem(FFT)
esp mat ble struct operator for fin void gist #include<iostream> #include<cstdio> #include<cstring> #include<cmath&
HDU1402:A * B Problem Plus——題解
|| name nbsp pro style plus string stream size http://acm.hdu.edu.cn/showproblem.php?pid=1402 給出兩個高精度正整數,求它們的積,最長的數長度不大於5e4。 FFT裸題,
HDU1042 A * B Problem Plus
itl namespace div mem accepted return sample tle esc A * B Problem Plus Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536
題解報告:hdu 1002 A + B Problem II(大數加法)
return 大數類 class family HERE contains urn integer ons Problem Description I have a very simple problem for you. Given two integers A and
HDU 1402 A*B
clas out har == using 3.1 int debug amp #include <bits/stdc++.h> using namespace std; typedef long long ll; #define ms(s,a) memset(
HDU-2101 A + B Problem Too(語法練習題)
A + B Problem Too Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 20917 Accepted Submissio
HDU - 2101 A + B Problem Too【水題】
A + B Problem Too Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 21290 Accepted Submissio
HDU 1002 A + B Problem II
A + B Problem II Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 439087
HDU-1000——A+B problem
A+B problem Calculate A + B. Input Each line will contain two integers A and B. Process to end of file. Output For eac
hdu刷題之路——hdu 1000 A + B Problem
hdu刷題之路 hdu 1000 A + B Problem (水題入門) Problem Description Calculate A + B. Input Each line will contain two integers A and B. Process to end
HDU 1002 ( A + B Problem II )
A + B Problem II Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) To