比赛 |
20121107 |
评测结果 |
AAAAA |
题目名称 |
三只小猪 |
最终得分 |
100 |
用户昵称 |
TBK |
运行时间 |
0.029 s |
代码语言 |
C++ |
内存使用 |
3.16 MiB |
提交时间 |
2012-11-07 10:19:31 |
显示代码纯文本
- #include <iostream>
- #include <cmath>
- #include <cstdio>
- #include <cstdlib>
- #include <cstring>
- #include <string>
- #include <set>
- #include <queue>
- #include <algorithm>
- #define MAXN 0x7fffffff
- using namespace std;
- int a,b,c,d,p1,q1;
- string str[51][51];
- char ch;
- void cheng(string &str1,string str2)
- {
- int e,l,m,n,p,q,v[1001]={0},u[1000],w[1000],x,y,z;
- string stri;
- m=str1.length();
- n=str2.length();
- m--;
- n--;
- for (p=0;p<=m;p++)
- u[p]=(int)str1[m-p]-'0';
- for (p=0;p<=n;p++)
- w[p]=(int)str2[n-p]-'0';
- for (p=0;p<=m;p++)
- for (q=0;q<=n;q++)
- {
- x=u[p]*w[q];
- y=x/10;
- z=x%10;
- l=p+q;
- v[l]=v[l]+z;
- v[l+1]=v[l+1]+v[l]/10+y;
- v[l]=v[l]%10;
- }
- e=m+n;
- if (v[e+1]!=0) e++;
- for (;e>=0;e--)
- if (v[e]!=0) break;
- p=e;
- for (e=p;e>=0;e--)
- stri+=(v[e]+'0');
- str1=stri;
- }
- void add(string &str1,string str2)
- {
- int e,l,m,n,p,v[1001]={0},u[1000]={0},w[1000]={0};
- string stri;
- m=str1.length();
- n=str2.length();
- m--;
- n--;
- l=m>n?m:n;
- for (p=0;p<=m;p++)
- u[p]=(int)str1[m-p]-'0';
- for (p=0;p<=n;p++)
- w[p]=(int)str2[n-p]-'0';
- for (p=0;p<=l;p++)
- {
- v[p]+=u[p]+w[p];
- if (v[p]>=10)
- {
- v[p]-=10;
- v[p+1]++;
- }
- }
- if (v[l+1]!=0) l++;
- for (e=l;e>=0;e--)
- stri+=(v[e]+'0');
- str1=stri;
- }
- int main(void)
- {
- freopen("piggy.in","r",stdin);
- freopen("piggy.out","w",stdout);
- scanf("%d",&a);
- for (p1=1;p1<=50;p1++)
- for (q1=p1+1;q1<=50;q1++)
- str[p1][q1]+="0";
- for (p1=1;p1<=50;p1++)
- str[p1][1]+="1";
- for (p1=2;p1<=50;p1++)
- for (q1=2;q1<=p1;q1++)
- {
- ch=q1/10+'0';
- string st="\0";
- str[p1][q1]=str[p1-1][q1];
- if (ch!='0') st+=ch;
- ch=q1%10+'0';
- st+=ch;
- if (str[p1][q1]!="0") cheng(str[p1][q1],st);
- add(str[p1][q1],str[p1-1][q1-1]);
- }
- for (b=0;b<a;b++)
- {
- scanf("%d%d",&c,&d);
- cout<<str[c][d]<<endl;
- }
- fclose(stdin);
- fclose(stdout);
- return 0;
- }