ZJU PAT 1012 有一个测试点过不去

Solar-Rain 2013-09-30 02:31:20
1012. The Best Rank (25)

时间限制
400 ms
内存限制
32000 kB
代码长度限制
16000 B
判题程序
Standard
作者
CHEN, Yue
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 Algrbra), 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



#include <iostream>
#include <string.h>
using namespace std;
const int MAX=2048;
int N,M;
int acme[MAX][7];
int m[MAX];
//互换
int Achange(int i,int j)
{
int t;
for(int k=0;k<7;++k)
{
t=acme[i][k];
acme[i][k]=acme[j][k];
acme[j][k]=t;
}
return 0;
}
//起泡排序
int Qqsort(int k,int low,int high)
{
if(low>=high)return 0;
int i=low;
while(i<high)
{
if(acme[i+1][k]>acme[i][k])
Achange(i,i+1);
++i;
}
Qqsort(k,low,i-1);
return 0;
}
int main()
{
freopen("in.txt","r",stdin);
freopen("out.txt","w",stdout);

scanf("%d %d",&N,&M);
int i=0,j=0,k=0,h=0;
for(;i<N;++i)
{
float t=0;
scanf("%d %d %d %d",&acme[i][0],&acme[i][3],&acme[i][2],&acme[i][1]);
t=(float)(acme[i][1]+acme[i][2]+acme[i][3])/3;
t+=0.5;
acme[i][4]=(int)t;
}
for(;j<M;++j)
scanf("%d",&m[j]);
Qqsort(4,0,N-1);
for(i=0;i<N;++i)
{
acme[i][5]=4;
if(acme[i][4]==acme[i-1][4]&&i>=1)
acme[i][6]=acme[i-1][6];
else
acme[i][6]=i+1;
}
for(j=3;j>=1;--j)
{
Qqsort(j,0,N-1);
int score=acme[0][j],scoreR=1;
for(i=0;i<N;++i)
{
if(acme[i][j]<score)++scoreR,score=acme[i][j];
if(scoreR<acme[i][6])
{

if(acme[i][j]==score)
acme[i][6]=scoreR;
else
{
acme[i][6]=i+1;
score=acme[i][j],scoreR=i+1;
}
acme[i][5]=j;
}
}
}
///输出
for(i=0;i<M;++i)
{
int ifprint=0;
for(j=0;j<N;++j)
{
if(m[i]==acme[j][0])
{
printf("%d ",acme[j][6]);
if(acme[j][5]==4)printf("A\n");
if(acme[j][5]==3)printf("C\n");
if(acme[j][5]==2)printf("M\n");
if(acme[j][5]==1)printf("E\n");
ifprint=1;
break;
}
}
if(ifprint==0)printf("N/A\n");
}
return 0;
}
...全文
306 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复
感觉
引用 5 楼 logiciel 的回复:
再给一个例子: 3 3 310101 98 85 88 310102 60 60 62 310103 60 60 63 310101 310102 310103 正确输出: 1 A 2 C 2 A 但LZ程序输出: 1 A 2 A 2 A 原因是LZ程序在计算平均分时加了0.5后取整数,这使得后两个学生的平均分相同。
感谢回答的正确,确实是这样的,这位观察的很仔细啊!!
logiciel 2013-10-01
  • 打赏
  • 举报
回复
再给一个例子: 3 3 310101 98 85 88 310102 60 60 62 310103 60 60 63 310101 310102 310103 正确输出: 1 A 2 C 2 A 但LZ程序输出: 1 A 2 A 2 A 原因是LZ程序在计算平均分时加了0.5后取整数,这使得后两个学生的平均分相同。
logiciel 2013-10-01
  • 打赏
  • 举报
回复
请试以下输入: 5 5 310101 98 85 88 310102 70 95 88 310103 82 87 94 310104 80 80 82 310105 82 82 83 310101 310102 310103 310104 310105 正确输出是: 1 A 1 M 1 E 4 C 2 C 但lz程序的输出是: 1 A 1 M 1 E 3 C 2 C 课程C有2个学生的分数是82分,分数为80分的应是第4而不是第3。
FancyMouse 2013-10-01
  • 打赏
  • 举报
回复
哦你输入的时候就是倒着的。那这里没问题。 问题在这里: if(scoreR<acme[i][6]) 满足这个条件但是acme[i][j]>score的时候你估计会输出错误的答案。
FancyMouse 2013-10-01
  • 打赏
  • 举报
回复
CME不是第一第二第三列么?你怎么变成第三第二第一列了?
Solar-Rain 2013-10-01
  • 打赏
  • 举报
回复
引用 4 楼 logiciel 的回复:
请试以下输入: 5 5 310101 98 85 88 310102 70 95 88 310103 82 87 94 310104 80 80 82 310105 82 82 83 310101 310102 310103 310104 310105 正确输出是: 1 A 1 M 1 E 4 C 2 C 但lz程序的输出是: 1 A 1 M 1 E 3 C 2 C 课程C有2个学生的分数是82分,分数为80分的应是第4而不是第3。
改了下面部分 for(i=0;i<N;++i) { if(acme[i][j]<score)scoreR=i+1; if(scoreR<acme[i][6]) { if(acme[i][j]==score) acme[i][6]=scoreR; else { scoreR=i+1; acme[i][6]=scoreR; score=acme[i][j]; } acme[i][5]=j; } score=acme[i][j]; } 终于A掉了
Solar-Rain 2013-10-01
  • 打赏
  • 举报
回复
引用 5 楼 logiciel 的回复:
再给一个例子: 3 3 310101 98 85 88 310102 60 60 62 310103 60 60 63 310101 310102 310103 正确输出: 1 A 2 C 2 A 但LZ程序输出: 1 A 2 A 2 A 原因是LZ程序在计算平均分时加了0.5后取整数,这使得后两个学生的平均分相同。
楼上的那个例子很有用,谢了啊 不过这里平均分 四舍五入 是考虑题目给的例子,其中第三行的平均分是 87.66,最后显示的是88,不过貌似这个点不是坑,取不取四舍五入好像都不影响。 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
hen_hao_ji 2013-09-30
  • 打赏
  • 举报
回复
baidu google : zju 1012

64,646

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧