比赛 20121107 评测结果 AAAAA
题目名称 三只小猪 最终得分 100
用户昵称 TBK 运行时间 0.029 s
代码语言 C++ 内存使用 3.16 MiB
提交时间 2012-11-07 10:19:31
显示代码纯文本
  1. #include <iostream>
  2. #include <cmath>
  3. #include <cstdio>
  4. #include <cstdlib>
  5. #include <cstring>
  6. #include <string>
  7. #include <set>
  8. #include <queue>
  9. #include <algorithm>
  10. #define MAXN 0x7fffffff
  11. using namespace std;
  12. int a,b,c,d,p1,q1;
  13. string str[51][51];
  14. char ch;
  15. void cheng(string &str1,string str2)
  16. {
  17. int e,l,m,n,p,q,v[1001]={0},u[1000],w[1000],x,y,z;
  18. string stri;
  19. m=str1.length();
  20. n=str2.length();
  21. m--;
  22. n--;
  23. for (p=0;p<=m;p++)
  24. u[p]=(int)str1[m-p]-'0';
  25. for (p=0;p<=n;p++)
  26. w[p]=(int)str2[n-p]-'0';
  27. for (p=0;p<=m;p++)
  28. for (q=0;q<=n;q++)
  29. {
  30. x=u[p]*w[q];
  31. y=x/10;
  32. z=x%10;
  33. l=p+q;
  34. v[l]=v[l]+z;
  35. v[l+1]=v[l+1]+v[l]/10+y;
  36. v[l]=v[l]%10;
  37. }
  38. e=m+n;
  39. if (v[e+1]!=0) e++;
  40. for (;e>=0;e--)
  41. if (v[e]!=0) break;
  42. p=e;
  43. for (e=p;e>=0;e--)
  44. stri+=(v[e]+'0');
  45. str1=stri;
  46. }
  47. void add(string &str1,string str2)
  48. {
  49. int e,l,m,n,p,v[1001]={0},u[1000]={0},w[1000]={0};
  50. string stri;
  51. m=str1.length();
  52. n=str2.length();
  53. m--;
  54. n--;
  55. l=m>n?m:n;
  56. for (p=0;p<=m;p++)
  57. u[p]=(int)str1[m-p]-'0';
  58. for (p=0;p<=n;p++)
  59. w[p]=(int)str2[n-p]-'0';
  60. for (p=0;p<=l;p++)
  61. {
  62. v[p]+=u[p]+w[p];
  63. if (v[p]>=10)
  64. {
  65. v[p]-=10;
  66. v[p+1]++;
  67. }
  68. }
  69. if (v[l+1]!=0) l++;
  70. for (e=l;e>=0;e--)
  71. stri+=(v[e]+'0');
  72. str1=stri;
  73. }
  74. int main(void)
  75. {
  76. freopen("piggy.in","r",stdin);
  77. freopen("piggy.out","w",stdout);
  78. scanf("%d",&a);
  79. for (p1=1;p1<=50;p1++)
  80. for (q1=p1+1;q1<=50;q1++)
  81. str[p1][q1]+="0";
  82. for (p1=1;p1<=50;p1++)
  83. str[p1][1]+="1";
  84. for (p1=2;p1<=50;p1++)
  85. for (q1=2;q1<=p1;q1++)
  86. {
  87. ch=q1/10+'0';
  88. string st="\0";
  89. str[p1][q1]=str[p1-1][q1];
  90. if (ch!='0') st+=ch;
  91. ch=q1%10+'0';
  92. st+=ch;
  93. if (str[p1][q1]!="0") cheng(str[p1][q1],st);
  94. add(str[p1][q1],str[p1-1][q1-1]);
  95. }
  96. for (b=0;b<a;b++)
  97. {
  98. scanf("%d%d",&c,&d);
  99. cout<<str[c][d]<<endl;
  100. }
  101. fclose(stdin);
  102. fclose(stdout);
  103. return 0;
  104. }