模拟--优先队列的多级比较函数

A Contesting Decision

Time Limit: 1000MS Memory Limit: 10000K
Total Submissions: 3601 Accepted: 2371

Description

Judging a programming contest is hard work, with demanding contestants, tedious decisions,and monotonous work. Not to mention the nutritional problems of spending 12 hours with only donuts, pizza, and soda for food. Still, it can be a lot of fun.
Software that automates the judging process is a great help, but the notorious unreliability of some contest software makes people wish that something better were available. You are part of a group trying to develop better, open source, contest management software, based on the principle of modular design.
Your component is to be used for calculating the scores of programming contest teams and determining a winner. You will be given the results from several teams and must determine the winner.
Scoring
There are two components to a team's score. The first is the number of problems solved. The second is penalty points, which reflects the amount of time and incorrect submissions made before the problem is solved. For each problem solved correctly, penalty points are charged equal to the time at which the problem was solved plus 20 minutes for each incorrect submission. No penalty points are added for problems that are never solved.
So if a team solved problem one on their second submission at twenty minutes, they are charged 40 penalty points. If they submit problem 2 three times, but do not solve it, they are charged no penalty points. If they submit problem 3 once and solve it at 120 minutes, they are charged 120 penalty points. Their total score is two problems solved with 160 penalty points.
The winner is the team that solves the most problems. If teams tie for solving the most problems,then the winner is the team with the fewest penalty points.

Input

For the programming contest your program is judging, there are four problems. You are guaranteed that the input will not result in a tie between teams after counting penalty points.
Line 1 < nTeams >
Line 2 - n+1 < Name > < p1Sub > < p1Time > < p2Sub > < p2Time > ... < p4Time >

The first element on the line is the team name, which contains no whitespace.Following that, for each of the four problems, is the number of times the team submitted a run for that problem and the time at which it was solved correctly (both integers). If a team did not solve a problem, the time will be zero. The number of submissions will be at least one if the problem was solved.

Output

The output consists of a single line listing the name of the team that won, the number of problems they solved, and their penalty points.

Sample Input

4
Stars 2 20 5 0 4 190 3 220
Rockets 5 180 1 0 2 0 3 100
Penguins 1 15 3 120 1 300 4 0
Marsupials 9 0 3 100 2 220 3 80

Sample Output

Penguins 3 475

Source

Mid-Atlantic 2003

#include<iostream>
#include<string>
#include<cstdio>
#include<queue>
using namespace std;

int nTeams;
string TeamName;
int Info[8];

class CTeam {
private:
	string TeamName;
	int SubmitNum[4];
	int SubmitTime[4];
	void CalculatePenalty() {
		for (int i = 0; i < 4; i++) {
			if (SubmitTime[i] != 0) {
				PenaltyTime += (SubmitNum[i] - 1) * 20 + SubmitTime[i];
				AcceptedNum++;
			}
		}
	}
public:
	//--优先队列用于排序比较的两个重要参数放在public作用域里面
	int AcceptedNum;
	int PenaltyTime;
	CTeam(const string& StringName, const int* info) {
		TeamName = StringName;
		AcceptedNum = 0; PenaltyTime = 0;
		for (int i = 0; i < 8; i += 2) {
			SubmitNum[i / 2] = info[i];
		}
		for (int i = 1; i < 8; i += 2) {
			SubmitTime[i / 2] = info[i];
		}
		CalculatePenalty();
	}
	//--const 放在函数名后面,说明该函数无法修改类的成员变量
	string ReturnStringName() const {
		return TeamName;
	}
};
//--小于号运算符重载函数
bool operator < (const CTeam& a, const CTeam& b) {
	if (a.AcceptedNum < b.AcceptedNum) {//--小于号是从大到小排序(大顶堆),堆顶存放最大的AC数量
		return true;
	}
	else if (a.AcceptedNum > b.AcceptedNum) {
		return false;
	}
	else {
		if (a.PenaltyTime > b.PenaltyTime) {//--大于号是从小到大排序(小顶堆),在AC数量相等的情况下,堆顶存放的是最小的罚时时间
			return true;
		}
		else {
			return false;
		}
	}
}

int main() {
	scanf("%d", &nTeams);
	priority_queue<CTeam> que;
	for (int i = 0; i < nTeams; i++) {
		cin >> TeamName;
		for (int j = 0; j < 8; j++) {
			scanf("%d", &Info[j]);
		}
		CTeam team(TeamName, Info);
		que.push(team);
	}
	CTeam Result = que.top();
	cout << Result.ReturnStringName();
	printf(" %d %d\n", Result.AcceptedNum, Result.PenaltyTime);
	return 0;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值