1012. The Best Rank (25)

题目:

To evaluate the performance of our first year CS majored students, we consider their grades of three courses only: C - C Programming Language, M - Mathematics (Calculus or Linear Algebra), and E - English. At the mean time, we encourage students by emphasizing on their best ranks -- that is, among the four ranks with respect to the three courses and the average grade, we print the best rank for each student.

For example, The grades of C, M, E and A - Average of 4 students are given as the following:

StudentID  C  M  E  A
310101     98 85 88 90
310102     70 95 88 84
310103     82 87 94 88
310104     91 91 91 91

Then the best ranks for all the students are No.1 since the 1st one has done the best in C Programming Language, while the 2nd one in Mathematics, the 3rd one in English, and the last one in average.

Input

Each input file contains one test case. Each case starts with a line containing 2 numbers N and M (<=2000), which are the total number of students, and the number of students who would check their ranks, respectively. Then N lines follow, each contains a student ID which is a string of 6 digits, followed by the three integer grades (in the range of [0, 100]) of that student in the order of C, M and E. Then there are M lines, each containing a student ID.

Output

For each of the M students, print in one line the best rank for him/her, and the symbol of the corresponding rank, separated by a space.

The priorities of the ranking methods are ordered as A > C > M > E. Hence if there are two or more ways for a student to obtain the same best rank, output the one with the highest priority.

If a student is not on the grading list, simply output "N/A".

Sample Input
5 6
310101 98 85 88
310102 70 95 88
310103 82 87 94
310104 91 91 91
310105 85 90 90
310101
310102
310103
310104
310105
999999
Sample Output
1 C
1 M
1 E
1 A
3 A
N/A

题解:

结构体排序,需要注意排名并列的情况,所以不应该简单的rank++,而是rank = i+1

代码:

#include <cstdio>
#include <algorithm>
using namespace std;
#define MAXN 1000010
struct stu{
	int id;
	int c, m, e, a;
	int bestRank;
	char best;
}buf[MAXN];
int cmp_a(stu a, stu b)
{
	return a.a > b.a;
}
int cmp_c(stu a, stu b)
{
	return a.c > b.c;
}
int cmp_m(stu a, stu b)
{
	return a.m > b.m;
}
int cmp_e(stu a, stu b)
{
	return a.e > b.e;
}
int main()
{
//	freopen("a.txt", "r", stdin);
	for(int i = 0; i < MAXN; i++)
		buf[i].bestRank = 0;
		
	int n, m;
	scanf("%d%d", &n, &m);
	stu *a = new stu[n];
	for(int i = 0; i < n; i++)
	{
		scanf("%d%d%d%d", &a[i].id, &a[i].c, &a[i].m, &a[i].e);
		a[i].a = (a[i].c + a[i].m + a[i].e) / 3;
	}
	sort(a, a + n, cmp_a);
	int rank = 1;
	a[0].bestRank = 1;
	a[0].best = 'A';
	for(int i = 1; i < n; i++)
	{
		if(a[i].a < a[i-1].a)
			rank = i + 1;
		a[i].bestRank = rank;
		a[i].best = 'A';
	}
	
	sort(a, a + n, cmp_c);
	rank = 1;
	if(a[0].bestRank != 1)
	{
		a[0].bestRank = 1;	
		a[0].best = 'C';
	}
	for(int i = 1; i < n; i++)
	{
		if(a[i].c < a[i-1].c)
			rank = i + 1;
		if(rank < a[i].bestRank)
		{
			a[i].bestRank = rank;
			a[i].best = 'C';
		}
	}
	
	sort(a, a + n, cmp_m);
	rank = 1;
	if(a[0].bestRank != 1)
	{
		a[0].bestRank = 1;
		a[0].best = 'M';
	}
	for(int i = 1; i < n; i++)
	{
		if(a[i].m < a[i-1].m)
			rank = i + 1;
		if(rank < a[i].bestRank)
		{
			a[i].bestRank = rank;
			a[i].best = 'M';
		}
	}
	
	sort(a, a + n, cmp_e);
	rank = 1;
	if(a[0].bestRank != 1)
	{
		a[0].bestRank = 1;
		a[0].best = 'E';
	}
	for(int i = 1; i < n; i++)
	{
		if(a[i].e < a[i-1].e)
			rank = i + 1;
		if(rank < a[i].bestRank)
		{
			a[i].bestRank = rank;
			a[i].best = 'E';
		}
	}
	
	for(int i = 0; i < n; i++)
	{
		buf[a[i].id] = a[i];
	}
	
	int query;
	while(m--)
	{
		scanf("%d", &query);
		if(buf[query].bestRank == 0)
			printf("N/A\n");
		else
			printf("%d %c\n", buf[query].bestRank, buf[query].best);
	}
	
	return 0;
}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
罗兰E.best是一款德国知名音乐合成器品牌罗兰(Roland)旗下的电子乐器系列。这个系列的产品包括键盘、电子架鼓和节奏机等,适用于各类音乐创作、演出和录制工作。 罗兰E.best系列的特点是声音质量出众,功能强大且易于操作。它们提供了很多不同的音色选择,如钢琴、吉他、合唱、合成、电流音、人声等。这些音色都经过专业的采样和处理,通过键盘或其他控制面板上的按钮和旋钮可以进行调节和变换。不仅如此,罗兰E.best还内置了各种效果器,比如混响、合唱、压缩、失真等,可以为音乐添加更多的表现力和情感。 除了出色的声音质量,罗兰E.best还具有丰富的功能。它们可以模拟不同乐器的演奏技法和特色效果,使得演奏更加真实和逼真。例如,可以通过操控键盘上的压力灵敏点以实现鼓和钢琴的弹奏技巧;还可以使用魔术鼓垫来模拟打击鼓的效果。此外,罗兰E.best还可以实时录制、编辑和混音音乐,支持多音轨录制和复杂的音频处理。 罗兰E.best系列的产品广泛应用于各类音乐制作场景,如音乐制作工作室、现场演出、个人演奏、DJ表演等。无论是专业乐手还是业余爱好者,都可以通过罗兰E.best找到适合自己的乐器,发挥出无限的创造力和表现力。 总之,罗兰E.best系列是一款功能强大、音色出众的电子乐器系列,在音乐制作和演奏领域有着广泛的应用和认可,是音乐爱好者们的不二选择。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值