<模板> Hdu 1402 A * B Problem Plus 大数乘法
2014-08-11 21:48
405 查看
A * B Problem Plus
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 12315 Accepted Submission(s): 2157
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
虽然还是没有AC。超时了。未解之谜,仔细再看看。
#include <cstdio> #include <cstdlib> #include <cstring> #include <algorithm> #include <iostream> #include <cmath> #include <queue> #include <map> #include <stack> #include <list> #include <vector> #define LL __int64 #define M 10000000000 using namespace std; LL a[5100],b[5100],c[110000]; char s1[500010],s2[500010]; void MUL() { int t,i,j; memset(c,0,sizeof(c)); for (i=a[0];i>0;i--) { t=a[0]-i+1; for (j=b[0];j>0;j--) { c[t+b[0]-j+1]+=a[i]*b[j] / M; c[t+b[0]-j]+=a[i]*b[j]%M; } if (c[t+1]) c[0]=t+1; else c[0]=t; } } int main() { while (gets(s1)) { gets(s2); strrev(s1); strrev(s2); int l1=strlen(s1)-1; int l2=strlen(s2)-1; memset(a,0,sizeof(0)); memset(b,0,sizeof(0)); while(l1>=0) { LL k=0,s=0; while (k<10 && l1>=0) { s=s*10+s1[l1]-'0'; k++; l1--; } a[0]++; a[a[0]]=s; } while(l2>=0) { int k=0,s=0; while (k<10 && l2>=0) { s=s*10+s2[l2]-'0'; k++; l2--; } b[0]++; b[b[0]]=s; } MUL(); printf("%I64d",c[c[0]]); for (int i=c[0]-1;i>1;i--) printf("%010I64d",c[i]); printf("%I64d\n",c[1]); //cout<<endl; } return 0; }
相关文章推荐
- <模板>zoj3696 Alien's Organ 概率论:泊松分布
- 在HTML中使用<script>做模板
- hdu 2084 数塔 <dp(模板)>
- HDU 1402 FFT模板题,求大数乘法
- <七>读<<大话设计模式>>之模板模型
- <七>阅读<<大话设计模式>>该模板模型
- <模板>米勒拉宾素数判定 题目是hdu4910
- <C++学习笔记>函数模板 template
- C++中template<class T> && template <typename T>(模板区分)
- HDU 1088 (模拟)使用<sstream>模版库
- 杭电 HDU 1402 A * B Problem Plus JavaJ大数
- <模板><计算几何>半平面求交学习小记
- <模板><计算几何>凸包及其基本算法
- <模板><计算几何>点与多边形的位置关系
- <<C++Primer PLus 第五版>>读书笔记4(终篇)
- <<C++Primer PLus 第五版>>读书笔记3
- <OJ_Sicily>Travelling Salesman Problem
- hdu--5128--计算几何<算不上.暴力模拟> && hdu--5131--初级cmp
- <模板> 矩形分割
- <模板><计算几何>求两向量夹角