programming-challenges Contest Scoreboard (110207) 题解

建立数据结构然后排序。第一次提交又犯了一个愚蠢的小错误。想想构造好的测试用例的能力也挺重要的。

#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 

using namespace std;

const int MAXTEAM = 110;
const int MAXPROBLEM = 11; 

struct Submit {
	int time;
	char status;
	Submit(int t, char s) : time(t), status(s) {

	}
};
bool operator<(Submit &p1, Submit &p2) {
	return p1.time < p2.time;
}

struct Team {
	int teamNum, correctProblem, usedTime; 
	vector submit[MAXPROBLEM];
	bool submitted; 

	void calculate() {
		for (int i = 1; i < MAXPROBLEM; i++) {
			sort(submit[i].begin(), submit[i].end());
		}
 
		for (int i = 1; i < MAXPROBLEM; i++) {
			int penaltyTime = 0;
			for (int j = 0; j < submit[i].size(); j++) {
				if (submit[i][j].status == 'C') {
					correctProblem++; 
					usedTime += submit[i][j].time;
					usedTime += penaltyTime;
					break;
				}
				else if (submit[i][j].status == 'I') {
					penaltyTime += 20;
				}
			}
		}
	}
};
bool operator<(Team &t1, Team t2) {
	return ((t1.correctProblem > t2.correctProblem) ||
		(t1.correctProblem == t2.correctProblem && t1.usedTime < t2.usedTime) ||
		(t1.correctProblem == t2.correctProblem && t1.usedTime == t2.usedTime && t1.teamNum < t2.teamNum));
}

vector teams(MAXTEAM);

void init() {
	for (int i = 0; i < MAXTEAM; i++) {
		teams[i].correctProblem = teams[i].usedTime = 0;
		teams[i].teamNum = i; 
		teams[i].submitted = false; 
		for (int j = 0; j < MAXPROBLEM; j++) teams[i].submit[j].clear();
	}
}

int main() {
	int TC; cin >> TC; 
	string s; getline(cin, s); getline(cin, s);
	bool blank = false; 
	for (int tc = 1; tc <= TC; tc++) {
		init(); 

		getline(cin, s); 
		while (!s.empty()) {
			stringstream ss(s); 
			int tteam, tproblem, ttime; char tstatus; 
			ss >> tteam >> tproblem >> ttime >> tstatus; 
			teams[tteam].submit[tproblem].push_back(Submit(ttime, tstatus)); 
			teams[tteam].submitted = true;

			getline(cin, s); 
		}
		
		for (int i = 1; i < MAXTEAM; i++) {
			teams[i].calculate(); 
		}

		if (blank) {
			cout << endl; 
		}
		blank = true;
		sort(teams.begin(), teams.end()); 
		for (int i = 0; i < teams.size(); i++) {
			if (teams[i].submitted) {
				cout << teams[i].teamNum << " " << teams[i].correctProblem << " " << teams[i].usedTime << endl; 
			}
		}
	}

	return 0; 
}


你可能感兴趣的:(算法)