1. 程式人生 > >hdu1402A * B Problem Plus

hdu1402A * B Problem Plus

#include<map>
#include<set>
#include<cmath>
#include<queue>
#include<bitset>
#include<math.h>
#include<cstdio>
#include<vector>
#include<string>
#include<cstring>
#include<iostream>
#include<algorithm>
#pragma comment(linker, "/STACK:102400000,102400000")
using namespace std;
const int N=50010;
const int MOD1=1000007;
const int MOD2=100000009;
const int MAX=1000000000;
const double EPS=0.00000001;
typedef long long ll;
const ll MOD=1000000007;
const ll INF=10000000010;
const double pi=acos(-1.0);
typedef double db;
typedef unsigned long long ull;
char s[N],t[N];
struct Complex{
    db r,i;
    Complex() {}
    Complex(db r,db i):r(r),i(i) {}
    Complex operator + (const Complex &t) const {
        return Complex(r+t.r,i+t.i);
    }
    Complex operator - (const Complex &t) const {
        return Complex(r-t.r,i-t.i);
    }
    Complex operator * (const Complex &t) const {
        return Complex(r*t.r-i*t.i,r*t.i+i*t.r);
    }
}a[3*N],b[3*N];
void FFT(Complex x[],int n,int rev) {
    int i,j,k,t,ds;
    Complex w,u,wn;
    for (i=1;i<n;i++) {
        for (j=0,t=i,k=n>>1;k;k>>=1,t>>=1) j=j<<1|t&1;
        if (i<j) swap(x[i],x[j]);
    }
    for (i=2,ds=1;i<=n;ds=i,i<<=1) {
        w=Complex(1,0);wn=Complex(cos(rev*2*pi/i),sin(rev*2*pi/i));
        for (j=0;j<ds;j++,w=w*wn)
            for (k=j;k<n;k+=i) {
                u=w*x[k+ds];x[k+ds]=x[k]-u;x[k]=x[k]+u;
            }
    }
    if (rev==-1) for (i=0;i<n;i++) x[i].r/=n;
}
int num[3*N];
void solve() {
    int i,k=0,n=1,les,let;
    les=strlen(s);
    let=strlen(t);
    while (n<les+let) n<<=1;
    for (i=0;i<les;i++) a[i]=Complex(s[les-i-1]-'0',0);
    for (i=les;i<n;i++) a[i]=Complex(0,0);
    for (i=0;i<let;i++) b[i]=Complex(t[let-i-1]-'0',0);
    for (i=let;i<n;i++) b[i]=Complex(0,0);
    FFT(a,n,1);FFT(b,n,1);
    for (i=0;i<n;i++) a[i]=a[i]*b[i];
    FFT(a,n,-1);
    for (i=0;i<n;i++) {
        k+=(int)(a[i].r+0.1);
        num[i]=k%10;k/=10;
    }
    while (k) { num[n++]=k%10;k/=10; }
    while (n>1&&!num[n-1]) n--;
    for (i=n-1;i>=0;i--) printf("%d", num[i]);
    printf("\n");
}
int main()
{
    while (scanf("%s%s", s, t)!=EOF) solve();
    return 0;
}


相關推薦

hdu1402A * B Problem Plus

#include<map> #include<set> #include<cmath> #include<queue> #include<bitset> #include<math.h> #include<cstdio> #i

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)

兩個 ret 處理 complex truct std spa strlen mes   因為剛學fft,想拿這題練練手,結果WA了個爽= =。   總結幾點犯的錯誤:   1.要註意處理前導零的問題。   2.一定要註意數組大小的問題。(前一個fft的題因為沒用到b數組,

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 - 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速度測試)

A * B Problem Plus Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 15111    Acc

hdu1402 A * B Problem Plus (FFT)

思路:考慮變成係數的形式,顯然就是兩個的多項式乘法,然後轉化成FFT,直接莽一波就完了。 #include<cstdio> #include<cmath> #include<cstring> #include<algorithm&

HDU 1402 A * B Problem Plus(FFT實現高精度乘法)

題意:50000位以內的高精度乘法。 思路:熟悉一下FFT的用法。多項式的乘法實際上是多項式係數向量的卷積,利用FFT進行多項式乘法,步驟如下: 1.補零:在兩個多項式的最前面補零,得到兩個2n次的多項式,設係數向量分別為v1,v2。 2.求值:用FFT計算f1 = DFT

hdu1402 A * B Problem Plus

很裸的FFT。 原理到處都有(看演算法導論就可以學懂了)。 #include<bits/stdc++.h> using namespace std; typedef complex<double> cpx; const int MAXN = 50

P1865 A % B Problem

code 輸入輸出 說明 tin else 描述 sca ++ return 題目背景 題目名稱是吸引你點進來的 實際上該題還是很水的 題目描述 區間質數個數 輸入輸出格式 輸入格式: 一行兩個整數 詢問次數n,範圍m 接下來n行,每行兩個整數 l,r

【數論線性篩】洛谷P1865 A%B problem

continue 個數 區間 str 輸出 數據 兩個 裸題 n) 題目背景 題目名稱是吸引你點進來的 實際上該題還是很水的 題目描述 區間質數個數 輸入輸出格式 輸入格式: 一行兩個整數 詢問次數n,範圍m 接下來n行,每行兩個整數 l,r 表示區間 輸出格式:

P1303 A*B Problem

cst clu ont tdi cnblogs ring b- max can 題目描述 求兩數的積。 輸入輸出格式 輸入格式: 兩個數 輸出格式: 積 輸入輸出樣例 輸入樣例#1: 1 2

HDOJ1002-A + B Problem II(高精加)

change test case logs names div lar struct () har Problem Description I have a very simple problem for you. Given two integers A and B,

loj6157 A^B Problem (並查集)

所有 是否 一個點 ron blank problem 異或 loj 遍歷 題目: https://loj.ac/problem/6157 分析: 這種樹上異或,一般是采用分位考慮,但是這題即使分位,也會發現非常不好處理 這裏考慮維護一個點到其根的路徑的異或值 用

HPU 1002 A + B Problem II【大數】

lar 保存 memory positive test size mod ack auth A + B Problem II Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/327

Week 1 # A A + B Problem II

res lines osi 可能 c代碼 turn contains inpu mean 原題描述: A - A + B Problem II I have a very simple problem for you. Given two integers A and B,

luogu1001 A+B Problem

而且 clas printf 一個 include main函數 int () div A+B Problem 題目描述 輸入兩個整數a,b,輸出它們的和(|a|,|b|<=10^9)。 註意 1、pascal使用integer會爆掉哦! 2、有負數哦! 3、c/c+

洛谷 P1303 A*B Problem(高精度乘法) 題解

正文 題目 names printf 精度 bool return max org 此文為博主原創題解,轉載時請通知博主,並把原文鏈接放在正文醒目位置。 題目鏈接 :https://www.luogu.org/problem/show?pid=1303 題目描述