[HDU1402] A * B Problem Plus

题意:高精度乘法

Solution: 将两个十进制数看作数列,卷积后暴力进位即可。

int main() {
    ios::sync_with_stdio(false);
    string x,y;
    while(cin>>x>>y) {
        poly a,b;
        a.c.resize(x.length());
        b.c.resize(y.length());
        int la=x.length(),lb=y.length();
        for(int i=0;i<la;i++) a.c[i]=x[la-i-1]-'0';
        for(int i=0;i<lb;i++) b.c[i]=y[lb-i-1]-'0';
        a*=b;
        for(int i=0;i<a.c.size();i++) a.c[i]=(int)(a.c[i]+0.5);
        for(int i=0;i<a.c.size()-1;i++) a.c[i+1]+=(int)(a.c[i]/10),a.c[i]=(int)(a.c[i])%10;
        for(int i=a.c.size()-1;i>=0;--i) if(a.c[i] == 0) a.c.pop_back(); else break;
        for(int i=a.c.size()-1;i>=0;--i) cout<<(int)(a.c[i]);
        if(a.c.size()==0) cout<<0;
        cout<<endl;
    }
}

原文地址:https://www.cnblogs.com/mollnn/p/11633480.html

时间: 2024-08-01 06:11:57

[HDU1402] A * B Problem Plus的相关文章

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): 12665    Accepted Submission(s): 2248 Problem Description Calculate A * B. Input Each line will contain two integers A and B. P

【NTT】hdu1402 A * B Problem Plus

r·2^k+1 r k g 3 1 1 2 5 1 2 2 17 1 4 3 97 3 5 5 193 3 6 5 257 1 8 3 7681 15 9 17 12289 3 12 11 40961 5 13 3 65537 1 16 3 786433 3 18 10 5767169 11 19 3 7340033 7 20 3 23068673 11 21 3 104857601 25 22 3 167772161 5 25 3 469762049 7 26 3 998244353 119

【FFT】hdu1402 A * B Problem Plus

FFT板子. 将大整数看作多项式,它们的乘积即多项式的乘积在x=10处的取值. #include<cstdio> #include<cmath> #include<cstring> #include<algorithm> using namespace std; #define EPS 1e-8 const double PI = acos(-1.0); struct Complex{ double real,image; Complex(double _r

HDU1402 A * B Problem Plus FFT

分析:网上别家的代码都分析的很好,我只是给我自己贴个代码,我是kuangbin的搬运工 一点想法:其实FFT就是快速求卷积罢了,当小数据的时候我们完全可以用母函数来做,比如那种硬币问题 FFT只是用来解决数据规模较大时的办法,可以达到nlogn的效率,大体原理就是运用了n次单位复根的折半引理 具体可以看算法导论 高度仰慕kuangbin大神的模板,实在是不想自己写 对于这个题,我们10^k的系数看成多项式系数,然后求卷积,进位就好了 #include <stdio.h> #include &l

[HDU1402]A * B Problem Plus(FFT)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1402 题意:大数乘法. 数太大,O(n^2)的不行,得用fft对乘法加速. 手推了一遍FFT的公式,感觉欧拉和分治很强,纪念我的第一发FFT. 1 #include <bits/stdc++.h> 2 using namespace std; 3 4 const double PI = acos(-1.0); 5 //复数结构体 6 typedef struct Complex { 7 doubl

[hdu1402]A * B Problem Plus(NTT)

解题关键:NTT模板 #include<cstdio> #include<cstring> #include<algorithm> #include<cstdlib> #include<iostream> #include<cmath> using namespace std; const int N=50010; typedef long long ll; ll G=3,P=469762049,a[3*N],b[3*N],wn[25

一步一步的无障碍理解快速傅立叶变换

/////////////////////////////////////////////////////////////////////////////////////////////////////// 作者:tt2767 声明:本文遵循以下协议自由转载-非商用-非衍生-保持署名|Creative Commons BY-NC-ND 3.0 查看本文更新与讨论请点击:http://blog.csdn.net/tt2767 链接被删请百度: CSDN tt2767 ///////////////

【HDU1402】【FFT】A * B Problem Plus

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 Out

【HDU1402】【FNT版】A * B Problem Plus

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 Out