UV problem solution: 10258-contest scoreboard

Source: Internet
Author: User

Understanding the problem specification is the very key to solve it:
1)... penalty time is computed... submission specified ed prior to the correct solution:
So if the AC submission (c) is before any other submission, you can ignore the later submissions to count penalty stuffs.
2)... lines of input are In the orderIn which submissions were inclued:
So for the input

1 1 10 C

1 1 10 I

You shoshould not count penalty... while

1 1 10 I

1 1 10 C

You shoshould count penalty.

Code:
  1. /*************************************** **********************************
  2. * Copyright (c) 2008 by liukaipeng *
  3. * Liukaipeng at gmail dot com *
  4. **************************************** *********************************/
  5. /* @ Judge_id 00000 10258 C ++ "contest scoreboard "*/
  6. # Include <algorithm>
  7. # Include <iostream>
  8. # Include <iterator>
  9. # Include <limits>
  10. # Include <string>
  11. # Include <sstream>
  12. # Include <vector>
  13. Using namespace STD;
  14. Struct submission
  15. {
  16. Int contestant;
  17. Int problem;
  18. Int time;
  19. Char status;
  20. };
  21. Bool operator> (istream & is, submission & SBM)
  22. {
  23. String line;
  24. Getline (is, line );
  25. If (! Line. Empty ()){
  26. Stringstream SS;
  27. SS <line;
  28. SS> SBM. contestant
  29. > SBM. Problem
  30. > SBM. Time
  31. > SBM. status;
  32. Return true;
  33. } Else {
  34. Return false;
  35. }
  36. }
  37. Struct submissioncmp
  38. {
  39. Bool operator () (submission const & S1, submission const & S2)
  40. {
  41. Return s1.contestant <s2.contestant? True:
  42. S1.contestant> s2.contestant? False:
  43. S1.problem <s2.problem? True:
  44. S1.problem> s2.problem? False:
  45. S1.time <s2.time;
  46. }
  47. };
  48. Struct score
  49. {
  50. Int contestant;
  51. Int solved;
  52. Int penalty;
  53. };
  54. Void operator <(ostream & OS, score const & SCR)
  55. {
  56. Cout <SCR. Contestant <''
  57. <SCR. Solved <''
  58. <SCR. Penalty <'/N ';
  59. }
  60. Struct scorecmp
  61. {
  62. Bool operator () (score const & S1, score const & S2)
  63. {
  64. Return s1.solved> s2.solved? True:
  65. S1.solved <s2.solved? False:
  66. S1.penalty <s2.penalty? True:
  67. S1.penalty> s2.penalty? False:
  68. S1.contestant <s2.contestant;
  69. }
  70. };
  71. Void compute_scores (vector <submission> & submissions,
  72. Vector <score> & scores)
  73. {
  74. Stable_sort (submissions. Begin (), submissions. End (), submissioncmp ());
  75. For (INT I = 0, size = submissions. Size (); I <size ;){
  76. Score scr = {submissions [I]. contestant, 0, 0 };
  77. For (; I <size & SCR. Contestant = submissions [I]. Contestant ;){
  78. Int problem = submissions [I]. problem;
  79. Int penalty = 0;
  80. Bool solved = false;
  81. For (; I <size & SCR. Contestant = submissions [I]. Contestant &&
  82. Problem = submissions [I]. problem; ++ I ){
  83. Char status = submissions [I]. status;
  84. If (! Solved ){
  85. If (status = 'C '){
  86. Solved = true;
  87. Penalty + = submissions [I]. time;
  88. } Else if (status = 'I '){
  89. Penalty + = 20;
  90. }
  91. }
  92. }
  93. If (solved ){
  94. SCR. Solved + = 1;
  95. SCR. Penalty + = penalty;
  96. }
  97. }
  98. Scores. push_back (SCR );
  99. }
  100. Sort (scores. Begin (), scores. End (), scorecmp ());
  101. }
  102. Int main (INT argc, char * argv [])
  103. {
  104. # Ifndef online_judge
  105. String name = argv [0];
  106. Freopen (name + ". In"). c_str (), "r", stdin );
  107. Freopen (name + ". Out"). c_str (), "W", stdout );
  108. # Endif
  109. Int ncases;
  110. Cin> ncases;
  111. Cin. Ignore (numeric_limits <streamsize>: max (), '/N ');
  112. Cin. Ignore (numeric_limits <streamsize>: max (), '/N ');
  113. While (ncases --> 0 ){
  114. Submission SBM;
  115. Vector <submission> submissions;
  116. While (CIN> SBM) submissions. push_back (SBM );
  117. Vector <score> scores;
  118. Compute_scores (submissions, scores );
  119. Copy (scores. Begin (), scores. End (), ostream_iterator <score> (cout ));
  120. If (ncases> 0) cout <'/N ';
  121. }
  122. Return 0;
  123. }

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.