记录编号 34038 评测结果 AAAAAAAAAA
题目名称 [NOIP 2011]瑞士轮 最终得分 100
用户昵称 GravatarQhelDIV 是否通过 通过
代码语言 C++ 运行时间 1.630 s
提交时间 2011-11-26 22:31:13 内存使用 10.14 MiB
显示代码纯文本
  1. #include <fstream>
  2. #include <cstdlib>
  3. using namespace std;
  4. ifstream fin("swiss.in");
  5. ofstream fout("swiss.out");
  6.  
  7. int N,R,Q;
  8.  
  9. class Competitor
  10. {
  11. public:
  12. int Score,Name,Energy;
  13. }Single[200001],A1[200001],A2[200001];
  14. int L1,L2;
  15. int Compare(const void *p,const void *q)
  16. {
  17. Competitor *p1=(Competitor *)p;
  18. Competitor *p2=(Competitor *)q;
  19. if(p1->Score == p2->Score)
  20. {
  21. if(p1->Name > p2->Name)
  22. return 1;
  23. else
  24. return -1;
  25. }
  26. else
  27. return p2->Score - p1->Score;
  28. }
  29.  
  30. int main()
  31. {
  32. int i,j,k;
  33. fin>>N>>R>>Q;
  34. N*=2;
  35. for(i=1;i<=N;i++)
  36. {
  37. fin>>Single[i].Score;
  38. Single[i].Name=i;
  39. }
  40. for(i=1;i<=N;i++)
  41. fin>>Single[i].Energy;
  42. qsort(Single+1,N,sizeof(Competitor),Compare);
  43. int p1,p2,L,p;
  44. for(i=1;i<=R;i++)
  45. {
  46. L1=0;L2=0;
  47. int Ti=N/2;
  48. for(j=1;j<=N;j++)
  49. {
  50. A1[j].Score=0;
  51. A2[j].Score=0;
  52. }
  53. for(j=1;j<=Ti;j++)
  54. {
  55. k=j<<1;
  56. if(Single[k].Energy > Single[k-1].Energy)
  57. {
  58. Single[k].Score++;
  59. A1[++L1]=Single[k];
  60. A2[++L2]=Single[k-1];
  61. }
  62. else
  63. {
  64. Single[k-1].Score++;
  65. A1[++L1]=Single[k-1];
  66. A2[++L2]=Single[k];
  67. }
  68. }
  69. p1=1;p2=1;L=L1;
  70. int q=0;
  71. for(j=1;j<N;j++)
  72. {
  73. if(A1[p1].Score > A2[p2].Score)
  74. Single[++q]=A1[p1++];
  75. else
  76. {
  77. if(A1[p1].Score < A2[p2].Score)
  78. Single[++q]=A2[p2++];
  79. else
  80. {
  81. if(A1[p1].Name > A2[p2].Name)
  82. Single[++q]=A2[p2++];
  83. else
  84. Single[++q]=A1[p1++];
  85. }
  86. }
  87. if(p1 > L1)
  88. {
  89. int d=p2;
  90. for(j=L1+1;j<=N;j++)
  91. Single[++q]=A2[d++];
  92. break;
  93. }
  94. if(p2 > L2)
  95. {
  96. int d=p1;
  97. for(j=L2+1;j<=N;j++)
  98. Single[++q]=A1[d++];
  99. break;
  100. }
  101. }
  102. }
  103. qsort(Single+1,N,sizeof(Competitor),Compare);
  104. fout<<Single[Q].Name;
  105. fin.close();
  106. fout.close();
  107. return 0;
  108. }