The ranklist of PAT is generated from the status list, which shows the scores of the submittions. 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 (<=104), the total number of users, K (<=5), the total number of problems, and M (<=105), the total number of submittions. 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 submittion in the following format:

user_id problem_id partial_score_obtained

where partial_score_obtained is either -1 if the submittion 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 -
 #include<cstdio>
#include<iostream>
#include<algorithm>
#include<string.h>
using namespace std;
typedef struct infoStruct{
int id;
int prob[];
int perfect;
int full;
int rank;
int shown;
infoStruct(){
perfect = ;
shown = ;
for(int i = ; i < ; i++)
prob[i] = -;
}
}info;
bool cmp(info a, info b){
if(a.full != b.full)
return a.full > b.full;
else if(a.perfect != b.perfect)
return a.perfect > b.perfect;
else return a.id < b.id;
}
info user[];
int main(){
int N, K, M, fullSco[];
int tempPro, tempSco, id;
scanf("%d%d%d", &N, &K, &M);
for(int i = ; i <= K; i++)
scanf("%d", &fullSco[i]);
for(int i = ; i <= N; i++)
user[i].id = i;
for(int i = ; i < M; i++){
scanf("%d%d%d", &id, &tempPro, &tempSco);
if(tempSco == fullSco[tempPro] && user[id].prob[tempPro] != fullSco[tempPro])
user[id].perfect++;
if(user[id].prob[tempPro] < tempSco){
user[id].prob[tempPro] = tempSco;
if(tempSco >= )
user[id].shown = ;
}
}
for(int i = ; i <= N; i++){
int ans = ;
for(int j = ; j <= K; j++){
if(user[i].prob[j] > )
ans += user[i].prob[j];
}
user[i].full = ans;
}
sort(user + , user + (N + ), cmp);
user[].rank = ;
for(int i = ; i <= N; i++){
if(user[i].full == user[i - ].full)
user[i].rank = user[i - ].rank;
else user[i].rank = i;
}
for(int i = ; i <= N; i++){
if(user[i].shown == ){
printf("%d %05d %d", user[i].rank, user[i].id, user[i].full);
for(int j = ; j <= K; j++){
if(user[i].prob[j] == -)
printf("");
else if(user[i].prob[j] == -)
printf(" -");
else printf(" %d", user[i].prob[j]);
}
printf("\n");
}
}
cin >> K;
return ;
}

总结:

1、这道题目比较麻烦,首先输入的数据是每个考生的全部提交信息,有可能一道题交多次,也可能一次也没交。最终要求统计输出每个考生的信息,按照总分排名顺序。这里有几个注意的地方。1)N个考生,他们的id是从1到N连续的,所以可以用int存储id,并且在输入时将id作为数组的下标,这样便于将同一个人的多次提交全部汇总。 2)未编译通过的题目(为-1)在计算总分时按0分算,在最终输出时也输出0。 3)全部未提交或者全部未编译成功的考生不做输出,但全为0分的考生需要输出。所以需要区分未提交、未编译通过、提交且编译通过但得分为0这三种情况。

2、struct的初始化

  typedef struct infoStruct{
    int id;
    int prob[6];
    int perfect;
    int full;
    int rank;
    int shown;
    infoStruct(){
      perfect = 0;
      shown = 0;
      for(int i = 0; i < 6; i++)
      prob[i] = -2;
    }
  }info;

3、起初写这道题时没有注意到题目里的id是从1到N连续的这一条件,盲目把struct里的id设置成了char数组型,导致每一条输入都需要从头开始找相同的id并作合并,复杂度变成了n^2,最后一个测试点超时。改为用int存储id,并将id映射为数组下标后,测试通过。今后在输入数据量较大的时候一定要先考虑到复杂度。算法超时的代码:

 #include<cstdio>
#include<iostream>
#include<algorithm>
#include<string.h>
using namespace std;
typedef struct infoStruct{
char id[];
int prob[];
int perfect;
int full;
int rank;
int shown;
infoStruct(){
perfect = ;
shown = ;
for(int i = ; i < ; i++)
prob[i] = -;
}
}info;
bool cmp(info a, info b){
if(a.full != b.full)
return a.full > b.full;
else if(a.perfect != b.perfect)
return a.perfect > b.perfect;
else return strcmp(a.id, b.id) < ;
}
info user[];
int main(){
int N, K, M, fullSco[];
char tempId[];
int tempPro, tempSco;
scanf("%d%d%d", &N, &K, &M);
for(int i = ; i <= K; i++)
scanf("%d", &fullSco[i]);
for(int i = , j = ; i < M; i++){
scanf("%s %d%d", tempId, &tempPro, &tempSco);
int index = -;
for(int k = ; k < j; k++){
if(strcmp(tempId, user[k].id) == ){
index = k;
break;
}
}
if(index == -){
index = j;
strcpy(user[index].id, tempId);
j++;
}
if(tempSco == fullSco[tempPro] && user[index].prob[tempPro] != fullSco[tempPro])
user[index].perfect++;
if(user[index].prob[tempPro] < tempSco){
user[index].prob[tempPro] = tempSco;
if(tempSco >= )
user[index].shown = ;
}
}
for(int i = ; i < N; i++){
int ans = ;
for(int j = ; j <= K; j++){
if(user[i].prob[j] > )
ans += user[i].prob[j];
}
user[i].full = ans;
}
sort(user, user + N, cmp);
user[].rank = ;
for(int i = ; i < N; i++){
if(user[i].full == user[i - ].full)
user[i].rank = user[i - ].rank;
else user[i].rank = i + ;
}
for(int i = ; i < N; i++){
if(user[i].shown == ){
printf("%d %s %d", user[i].rank, user[i].id, user[i].full);
for(int j = ; j <= K; j++){
if(user[i].prob[j] == -)
printf("");
else if(user[i].prob[j] == -)
printf(" -");
else printf(" %d", user[i].prob[j]);
}
printf("\n");
}
}
cin >> K;
return ;
}

A1075. PAT Judge的更多相关文章

  1. A1075 PAT Judge (25)(25 分)

    A1075 PAT Judge (25)(25 分) The ranklist of PAT is generated from the status list, which shows the sc ...

  2. PAT A1075 PAT Judge (25 分)——结构体初始化,排序

    The ranklist of PAT is generated from the status list, which shows the scores of the submissions. Th ...

  3. A1075 PAT Judge (25 分)

    The ranklist of PAT is generated from the status list, which shows the scores of the submissions. Th ...

  4. PAT甲级——A1075 PAT Judge

    The ranklist of PAT is generated from the status list, which shows the scores of the submissions. Th ...

  5. PAT_A1075#PAT Judge

    Source: PAT A1075 PAT Judge (25 分) Description: The ranklist of PAT is generated from the status lis ...

  6. PAT 1075 PAT Judge[比较]

    1075 PAT Judge (25 分) The ranklist of PAT is generated from the status list, which shows the scores ...

  7. PTA 10-排序5 PAT Judge (25分)

    题目地址 https://pta.patest.cn/pta/test/16/exam/4/question/677 5-15 PAT Judge   (25分) The ranklist of PA ...

  8. PAT 甲级 1075 PAT Judge (25分)(较简单,注意细节)

    1075 PAT Judge (25分)   The ranklist of PAT is generated from the status list, which shows the scores ...

  9. PAT Judge

    原题连接:https://pta.patest.cn/pta/test/16/exam/4/question/677 题目如下: The ranklist of PAT is generated fr ...

随机推荐

  1. python基础知识小结-运维笔记

    接触python已有一段时间了,下面针对python基础知识的使用做一完整梳理:1)避免‘\n’等特殊字符的两种方式: a)利用转义字符‘\’ b)利用原始字符‘r’ print r'c:\now' ...

  2. 安卓开发helloworld

    https://blog.csdn.net/tangjie134/article/details/79495204

  3. 对于VS软件的个人评价

    因为还是一个菜鸟,对于VS这样的大软件还只能是自己个人的理解,以前用的是VC++,后来因为电脑系统更新,开始接触了VS,个人觉得还是vs2010更好用一些,作为一款windows平台应用程序的集成开发 ...

  4. Linux内核分析——字符集总结与分析

      一.  设置修改系统.应用默认字符集 1. 查看虚拟机的字符集: 由此可见,该虚拟机的字符集为zh_CN.UTF-8. 2. 查看服务器支持的编码方式 3. 修改字符集类型 上图可见,LANG字符 ...

  5. Linux课题实践一

    Linux课题实践一 20135318 刘浩晨 1.1应用安装 (1)掌握软件源的维护方法,配置系统使用软件源镜像  删除过期或者重复的软件包:进入”系统设置“-”软件和更新”-”ubuntu软件“- ...

  6. hbase 1.2.1 分布式安装

    1.机器信息 五台centos 64位机器 2.集群规划 Server Name Hadoop Cluster Zookeeper   Ensemble HBase Cluster Ip   Hado ...

  7. C++拷贝构造函数的调用时机

    一.拷贝构造函数调用的时机 ​ 当以拷贝的方式初始化对象时会调用拷贝构造函数,这里需要注意两个关键点,分别是以拷贝的方式和初始化对象 1. 初始化对象 初始化对象是指,为对象分配内存后第一次向内存中填 ...

  8. 研究VCL源码的原因和起点

    ---恢复内容开始--- 研究VCL源码的原因和起点 根本原因:当然是希望自己成为Delphi高手,因为这么多年过去,觉得自己始终不得要领,修改一个控件都无从下手,一直都只是个会拖控件的白痴.而我却拥 ...

  9. git常用命令及用法小计

    git init 初始化一个本地git仓库repository git status 查看状态 git add <file> 将工作区修改加到暂存区(stage) git commit - ...

  10. SpringMVC @SessionAttributes 使用

    @SessionAttributes 只能作用在类上,作用是将指定的Model中的键值对添加至session中,方便在下一次请求中使用. 简单示例 目标是通过 @SessionAttributes 注 ...