programming-challenges Contest Scoreboard (110207) 题解

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

#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <stack>
#include <assert.h>
#include <algorithm>
#include <math.h>
#include <ctime>
#include <functional>
#include <string.h>
#include <stdio.h>
#include <numeric>
#include <float.h>

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> 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<Team> 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; 
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值