记录编号 197477 评测结果 AAAAAAAAAA
题目名称 [NOIP 2012]国王游戏 最终得分 100
用户昵称 Gravatarlingyixiaoyao 是否通过 通过
代码语言 C++ 运行时间 0.064 s
提交时间 2015-10-23 21:43:55 内存使用 0.38 MiB
显示代码纯文本
  1. #include <iostream>
  2. #include <cstdio>
  3. #include <cstring>
  4. #include <algorithm>
  5. using namespace std;
  6.  
  7. struct node
  8. {
  9. int x,y,w;
  10. };
  11.  
  12. const int maxn=1000+10;
  13. int n;
  14. node a[maxn];
  15. int x[5000],y[5000],ans[5000];
  16. int lenx,leny,len;
  17.  
  18. bool comp(node i,node j);
  19. void chu(int m);
  20. void cheng(int m);
  21. bool ok();
  22.  
  23. int main()
  24. {
  25. freopen("kinggame.in","r",stdin);
  26. freopen("kinggame.out","w",stdout);
  27. cin>>n;
  28. for (int i=0; i<=n; i++)
  29. {
  30. cin>>a[i].x>>a[i].y;
  31. a[i].w=a[i].x*a[i].y;
  32. }
  33. sort(a+1,a+n+1,comp);
  34. //x=a[0].x;
  35. x[1]=a[0].x; lenx=1;
  36. for (int i=1; i<=n; i++)
  37. {
  38. //y=x/a[i].y;
  39. chu(a[i].y);
  40. //if (y>ans) ans=y;
  41. if (ok())
  42. {
  43. len=leny;
  44. memcpy(ans,y,sizeof(y));
  45. }
  46. //x*=a[i].x;
  47. cheng(a[i].x);
  48. }
  49. for (int i=len; i>=1; i--)
  50. cout<<ans[i];
  51. cout<<endl;
  52. return 0;
  53. }
  54. bool comp(node i,node j)
  55. {
  56. if (i.w<j.w) return true;
  57. else return false;
  58. }
  59. void chu(int m)
  60. {
  61. memset(y,0,sizeof(y));
  62. int d=0;
  63. int p=lenx;
  64. leny=lenx;
  65. while (p>0)
  66. {
  67. d=d*10+x[p];
  68. y[p]=d/m;
  69. d%=m;
  70. p--;
  71. }
  72. while (leny>0 && y[leny]==0) leny--;
  73. }
  74. void cheng(int m)
  75. {
  76. for (int i=1; i<=lenx; i++)
  77. {
  78. x[i]*=m;
  79. }
  80. for (int i=1; i<=lenx; i++)//处理进位
  81. {
  82. x[i+1]+=x[i]/10;
  83. x[i]%=10;
  84. }
  85. while(x[lenx+1]>0)//处理高位
  86. {
  87. lenx++;
  88. x[lenx+1]+=x[lenx]/10;
  89. x[lenx]%=10;
  90. }
  91. }
  92. bool ok()//判断是否更大
  93. {
  94. if (leny>len) return true;
  95. if (leny==len)
  96. {
  97. int p=len;
  98. while (p>0)
  99. {
  100. if (y[p]>ans[p]) return true;
  101. p--;
  102. }
  103. }
  104. return false;
  105. }