BZOJ1754: [Usaco2005 qua]Bull Math
2014-10-17 18:20
323 查看
1754: [Usaco2005 qua]Bull Math
Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 374 Solved: 227
[Submit][Status]
Description
Bulls are so much better at math than the cows. They can multiplyhuge integers together and get perfectly precise answers ... or so
they say. Farmer John wonders if their answers are correct. Help
him check the bulls' answers. Read in two positive integers (no
more than 40 digits each) and compute their product. Output it as
a normal number (with no extra leading zeros).
FJ asks that you do this yourself; don't use a special library
function for the multiplication.
输入两个数,输出其乘积
Input
* Lines 1..2: Each line contains a single decimal number.Output
* Line 1: The exact product of the two input linesSample Input
111111111111111111111111
Sample Output
12345679011110987654321HINT
Source
Gold题解:
呵呵,金组出这种题,防爆零呢吧。。。
代码:
#include<cstdio> #include<cstdlib> #include<cmath> #include<cstring> #include<algorithm> #include<iostream> #include<vector> #include<map> #include<set> #include<queue> #include<string> #define inf 1000000000 #define maxn 10000 #define maxm 500+100 #define eps 1e-10 #define ll long long #define pa pair<int,int> #define for0(i,n) for(int i=0;i<=(n);i++) #define for1(i,n) for(int i=1;i<=(n);i++) #define for2(i,x,y) for(int i=(x);i<=(y);i++) #define for3(i,x,y) for(int i=(x);i>=(y);i--) #define mod 1000000007 using namespace std; inline int read() { int x=0,f=1;char ch=getchar(); while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();} while(ch>='0'&&ch<='9'){x=10*x+ch-'0';ch=getchar();} return x*f; } int n,m,a[maxn],b[maxn],c[maxn]; char ch; int main() { freopen("input.txt","r",stdin); freopen("output.txt","w",stdout); ch=getchar(); while(ch<='9'&&ch>='0')a[++n]=ch-'0',ch=getchar(); for1(i,n>>1)swap(a[i],a[n+1-i]); ch=getchar(); while(ch<='9'&&ch>='0')b[++m]=ch-'0',ch=getchar(); for1(i,m>>1)swap(b[i],b[m+1-i]); for1(i,n) for1(j,m) c[i+j-1]+=a[i]*b[j]; for1(i,n+m)c[i+1]+=c[i]/10,c[i]%=10; int t=n+m; while(!c[t])t--; for3(i,t,1)printf("%d",c[i]); printf("\n"); return 0; }
View Code
相关文章推荐
- bzoj1754 [Usaco2005 qua]Bull Math
- bzoj1754 [Usaco2005 qua]Bull Math
- bzoj1754 [Usaco2005 qua]Bull Math
- BZOJ 1754: [Usaco2005 qua]Bull Math
- bzoj 1754: [Usaco2005 qua]Bull Math
- BZOJ 1754: [Usaco2005 qua]Bull Math 高精乘
- 【BZOJ】1754: [Usaco2005 qua]Bull Math
- bzoj1754: [Usaco2005 qua]Bull Math
- bzoj 1754: [Usaco2005 qua]Bull Math【高精乘法】
- 1754: [Usaco2005 qua]Bull Math (高精度乘法)
- 1754: [Usaco2005 qua]Bull Math
- bzoj1752 [Usaco2005 qua]Til the Cows Come Home
- bzoj1752 [Usaco2005 qua]Til the Cows Come Home
- bzoj1753 [Usaco2005 qua]Who's in the Middle
- bzoj1753 [Usaco2005 qua]Who's in the Middle
- [bzoj1751][Usaco2005 qua]Lake Counting
- bzoj 1753: [Usaco2005 qua]Who's in the Middle【排序】
- BZOJ 3384: [Usaco2004 Nov]Apple Catching 接苹果/BZOJ 1750: [Usaco2005 qua]Apple Catching dp
- bzoj1753 [Usaco2005 qua]Who's in the Middle
- bzoj1750 [Usaco2005 qua]Apple Catching