1075 PAT Judge (25 分)

本文详细解析了PAT竞赛中排名系统的实现方法,包括如何处理用户的多次提交、如何计算总分和排名,以及如何处理未提交解决方案的情况。文章通过具体示例展示了如何使用C++进行编程实现,对于理解竞赛排名逻辑和提升编程技能具有一定的指导意义。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

The ranklist of PAT is generated from the status list, which shows the scores of the submissions. This time you are supposed to generate the ranklist for PAT.

Input Specification:
Each input file contains one test case. For each case, the first line contains 3 positive integers, N (≤10
​4
​​ ), the total number of users, K (≤5), the total number of problems, and M (≤10
​5
​​ ), the total number of submissions. It is then assumed that the user id’s are 5-digit numbers from 00001 to N, and the problem id’s are from 1 to K. The next line contains K positive integers p[i] (i=1, …, K), where p[i] corresponds to the full mark of the i-th problem. Then M lines follow, each gives the information of a submission in the following format:

user_id problem_id partial_score_obtained
where partial_score_obtained is either −1 if the submission cannot even pass the compiler, or is an integer in the range [0, p[problem_id]]. All the numbers in a line are separated by a space.

Output Specification:
For each test case, you are supposed to output the ranklist in the following format:

rank user_id total_score s[1] … s[K]
where rank is calculated according to the total_score, and all the users with the same total_score obtain the same rank; and s[i] is the partial score obtained for the i-th problem. If a user has never submitted a solution for a problem, then “-” must be printed at the corresponding position. If a user has submitted several solutions to solve one problem, then the highest score will be counted.

The ranklist must be printed in non-decreasing order of the ranks. For those who have the same rank, users must be sorted in nonincreasing order according to the number of perfectly solved problems. And if there is still a tie, then they must be printed in increasing order of their id’s. For those who has never submitted any solution that can pass the compiler, or has never submitted any solution, they must NOT be shown on the ranklist. It is guaranteed that at least one user can be shown on the ranklist.

Sample Input:
7 4 20
20 25 25 30
00002 2 12
00007 4 17
00005 1 19
00007 2 25
00005 1 20
00002 2 2
00005 1 15
00001 1 18
00004 3 25
00002 2 25
00005 3 22
00006 4 -1
00001 2 18
00002 1 20
00004 1 15
00002 4 18
00001 3 4
00001 4 2
00005 2 -1
00004 2 0
Sample Output:
1 00002 63 20 25 - 18
2 00005 42 20 0 22 -
2 00007 42 - 25 - 17
2 00001 42 18 18 4 2
5 00004 40 15 0 25 -

这道题是有点坑,包括最后一个测试点,但是也不是完完全全地坑人,我认为如果你总是提交不过,我建议你仔细读题,逐字逐句地看。
重点关注这几句

If a user has never submitted a solution for a problem, then “-” must be printed at the corresponding position. If a user has submitted several solutions to solve one problem, then the highest score will be counted.

编译失败的题的分数要置为0,但不是每次遇到-1都要置为0,我们一开始把所有的题分数置为-1,只有第一次遇到才会置为0,最后还为-1的题目要输出"-",另外,高分会覆盖低分。

For those who has never submitted any solution that can pass the compiler, or has never submitted any solution, they must NOT be shown on the ranklist

只要有一道题的分数大于等于0,就可以输出

For those who have the same rank, users must be sorted in nonincreasing order according to the number of perfectly solved problems.

输入题目的满分值作用在这里,不是没有用处,但是输入的第一个整数确实没有用处(或者说可以不用)。

这种排名的输出方式在乙级已经介绍过,就不赘述了。

#include<iostream>
#include<vector>
#include<map>
#include<algorithm>
using namespace std;
bool rule(const vector<int>& a, const vector<int>& b)
{
	return a[1] == b[1] ? a[a.size() - 1] == b[b.size() - 1] ? a[0]<b[0] : a[a.size() - 1] > b[b.size() - 1] : a[1] > b[1];
}
int main()
{
	int id, totalquestion, a, b, score;
	map<int,vector<int>>res;
	vector<vector<int>>re;
	scanf("%d %d %d", &id, &totalquestion, &a);
	vector<int>fullscore(totalquestion + 1);
	for (int i = 0; i < totalquestion; i++)
		scanf("%d", &fullscore[i + 1]);
	for (int i = 0; i < a; i++)
	{
		scanf("%d %d %d", &id, &b, &score);
		if (!res[id].size())
			res[id].resize(totalquestion + 3, -1);//预留了三个位置,分别用来存ID,是否可以输出的标志以及得到满分的题目的个数
		if (score > res[id][b])
		{
			res[id][res[id].size() - 2] = 1;
			res[id][b] = score;
		}
		else if (res[id][b] == -1)
			res[id][b] = 0;
	}
	for (auto it : res)
	{
		vector<int>tmp;
		for (int i = 0; i < it.second.size() - 2; i++)
		{
			if (i > 0 && it.second[i] == fullscore[i])
				it.second[it.second.size() - 1]++;
			i == 0 ? it.second[0] = 0 : it.second[0] += it.second[i] >= 0 ? it.second[i] : 0;
			if (i)
				tmp.push_back(it.second[i]);
		}
		tmp.insert(tmp.begin(), it.second[0]);
		tmp.insert(tmp.begin(), it.first);
		tmp.push_back(it.second[it.second.size() - 2]);
		tmp.push_back(it.second[it.second.size() - 1]);
		re.push_back(tmp);
	}
	sort(re.begin(), re.end(), rule);
	for (int i = 0, k = 0, last = 0; i < re.size() && re[i][re[i].size() - 2] == 1; i++)
	{
		if (re[i][1] != last)
		{
			cout << i + 1;
			last = re[i][1];
			k = i + 1;
		}
		else
			printf("%d", k);
		for (int j = 0; j < re[i].size() - 2; j++)
			if (j == 0)
				printf(" %05d", re[i][j]);
			else if (re[i][j] >= 0)
				printf(" %d", re[i][j]);
			else
				printf(" -");
		printf("\n");
	}
	return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值