UVa Problem Solution: 10258 - Contest Scoreboard
来源:互联网 发布:淘宝爆款知乎 编辑:程序博客网 时间:2024/05/22 12:35
Understanding the problem specification is the very key to solve it:
1) ... penalty time is computed ... submission received 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 order in which submissions were received:
So for the input
1 1 10 C
1 1 10 I
you should not count penalty... while
1 1 10 I
1 1 10 C
you should count penalty.
Code:
- /*************************************************************************
- * Copyright (C) 2008 by liukaipeng *
- * liukaipeng at gmail dot com *
- *************************************************************************/
- /* @JUDGE_ID 00000 10258 C++ "Contest Scoreboard" */
- #include <algorithm>
- #include <iostream>
- #include <iterator>
- #include <limits>
- #include <string>
- #include <sstream>
- #include <vector>
- using namespace std;
- struct submission
- {
- int contestant;
- int problem;
- int time;
- char status;
- };
- bool operator>>(istream& is, submission& sbm)
- {
- string line;
- getline(is, line);
- if (!line.empty()) {
- stringstream ss;
- ss << line;
- ss >> sbm.contestant
- >> sbm.problem
- >> sbm.time
- >> sbm.status;
- return true;
- } else {
- return false;
- }
- }
- struct submissioncmp
- {
- bool operator()(submission const& s1, submission const& s2)
- {
- return s1.contestant < s2.contestant ? true :
- s1.contestant > s2.contestant ? false :
- s1.problem < s2.problem ? true :
- s1.problem > s2.problem ? false :
- s1.time < s2.time;
- }
- };
- struct score
- {
- int contestant;
- int solved;
- int penalty;
- };
- void operator<<(ostream& os, score const& scr)
- {
- cout << scr.contestant << ' '
- << scr.solved << ' '
- << scr.penalty << '/n';
- }
- struct scorecmp
- {
- bool operator()(score const& s1, score const& s2)
- {
- return s1.solved > s2.solved ? true :
- s1.solved < s2.solved ? false :
- s1.penalty < s2.penalty ? true :
- s1.penalty > s2.penalty ? false :
- s1.contestant < s2.contestant;
- }
- };
- void compute_scores(vector<submission>& submissions,
- vector<score>& scores)
- {
- stable_sort(submissions.begin(), submissions.end(), submissioncmp());
- for (int i = 0, size = submissions.size(); i < size; ) {
- score scr = {submissions[i].contestant, 0, 0};
- for (; i < size && scr.contestant == submissions[i].contestant; ) {
- int problem = submissions[i].problem;
- int penalty = 0;
- bool solved = false;
- for (; i < size && scr.contestant == submissions[i].contestant &&
- problem == submissions[i].problem; ++i) {
- char status = submissions[i].status;
- if (!solved) {
- if (status == 'C') {
- solved = true;
- penalty += submissions[i].time;
- } else if (status == 'I') {
- penalty += 20;
- }
- }
- }
- if (solved) {
- scr.solved += 1;
- scr.penalty += penalty;
- }
- }
- scores.push_back(scr);
- }
- sort(scores.begin(), scores.end(), scorecmp());
- }
- int main(int argc, char *argv[])
- {
- #ifndef ONLINE_JUDGE
- string name = argv[0];
- freopen((name + ".in").c_str(), "r", stdin);
- freopen((name + ".out").c_str(), "w", stdout);
- #endif
- int ncases;
- cin >> ncases;
- cin.ignore(numeric_limits<streamsize>::max(), '/n');
- cin.ignore(numeric_limits<streamsize>::max(), '/n');
- while (ncases-- > 0) {
- submission sbm;
- vector<submission> submissions;
- while (cin >> sbm) submissions.push_back(sbm);
- vector<score> scores;
- compute_scores(submissions, scores);
- copy(scores.begin(), scores.end(), ostream_iterator<score>(cout));
- if (ncases > 0) cout << '/n';
- }
- return 0;
- }
- UVa Problem Solution: 10258 - Contest Scoreboard
- uva 10258 - Contest Scoreboard
- UVa 10258 - Contest Scoreboard
- UVA 10258 Contest Scoreboard
- UVA 10258 Contest Scoreboard
- UVa 10258 Contest Scoreboard
- UVa 10258 - Contest Scoreboard
- Uva 10258 Contest Scoreboard
- UVA 10258 Contest Scoreboard
- uva 10258Contest Scoreboard
- UVa Problem 10258 Contest Scoreboard (比赛计分板)
- UVa OJ 10258 - Contest Scoreboard
- 10258 - Contest Scoreboard
- Contest Scoreboard
- UVa Problem Solution: 10189 - Minesweeper
- UVa Problem Solution: 10033 - Interpreter
- UVa Problem Solution: 10050 - Hartals
- UVa Problem Solution: 10149 - Yahtzee
- svn安装 以及在eclipse中的配置
- 找工作瞬联篇
- 2008网络盛典年度网络流行语候选:山寨
- Eclipse常用快捷键和使用技巧
- 冬天真的来了
- UVa Problem Solution: 10258 - Contest Scoreboard
- nginx+php+fastcg+xcache+mysql+openx
- How to install PHP-FPM (spawn-fcgi replacement)
- C++ TCP Server
- Radio Button的使用
- 帮个忙!!!
- 枸杞子滋补美容
- 超级玛丽制作揭秘9精灵结构struct ROLE
- 如何动态加载c++函数和类