题目地址

https://pta.patest.cn/pta/test/16/exam/4/question/677

5-15 PAT Judge   (25分)

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, NN (\le 10^4≤10​4​​), the total number of users, KK (\le 5≤5), the total number of problems, and MM (\le 10^5≤10​5​​), the total number of submissions. It is then assumed that the user id's are 5-digit numbers from 00001 to NN, and the problem id's are from 1 to KK. The next line contains KK positive integers p[i] (i=1, ..., KK), where p[i]corresponds to the full mark of the i-th problem. Then MM 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−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_scoreobtain 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 -
/*
评测结果
时间 结果 得分 题目 编译器 用时(ms) 内存(MB) 用户
2017-07-06 22:51 答案正确 25 5-15 gcc 153 2
测试点结果
测试点 结果 得分/满分 用时(ms) 内存(MB)
测试点1 答案正确 13/13 13 1
测试点2 答案正确 3/3 2 1
测试点3 答案正确 3/3 14 1
测试点4 答案正确 3/3 2 1
测试点5 答案正确 3/3 153 2 思路:因为是结构体排序,如果省事可以做结构体的swap,不过开销太大。虽然能过也能过,但这题考察的应该是间接排序,那就拿间接排序做了。 对于分数相同采取的措施:因为总分数不高,若把AC数量作为第二关键字,那么算一个排序分数出来就好了,为总分x10+全过次数。
因为用的插排,ID顺序不会乱,所以ID是递增有序的。
如果要求再复杂点只能做个比较函数了,传进去处理完给个返回值,看哪个该排在前面。 容易踩的坑——对提交分数为-1的处理:题读了好几遍才明白这里的细节,编译失败算0,不算未提交
但是不能直接算作0,虽然在分数上计作0,但是应该在用户信息表中额外维护一个该用户是否成功提交过的标识符。 对重复AC的处理——刚开始最后一个点拿不到分数,因为有重复满分提交。
发现此时没有把AC次数+1的判断嵌套到上面的if里面,属于失误。
*/
#include <stdio.h>
#define UNSUBMITTED -1
#define MAXN 100000
#define MAXK 5
struct userinfo
{
int totalScore;
int allClearCount;
int rank;
int pointForSort;
int eversubmitted;
} gUserInfo[MAXN]; int gProblemTable[MAXK];
int gSubmissions[MAXN][MAXK];
int gRanklist[MAXN]; void InitSubmissions(int N,int K)
{
int i,j;
for(i=0;i<N;i++)
for(j=0;j<K;j++)
gSubmissions[i][j]=UNSUBMITTED;
}
void InitRanklist()
{
int i;
for(i=0;i<MAXN;i++)
gRanklist[i]=i;
} void CalcTotalScore(int N,int K)
{
int i,j;
for(i=0;i<N;i++)
for(j=0;j<K;j++)
{
if(gSubmissions[i][j]>0)
gUserInfo[i].totalScore+=gSubmissions[i][j];
}
} void IndriectInsertionSort(int N)
{
int i,j,temp;
for(i=1;i<N;i++)
{
j=i;
temp=gRanklist[j];
while(j>0)
{
if (gUserInfo[temp].pointForSort>gUserInfo[gRanklist[j-1]].pointForSort)
{
gRanklist[j]=gRanklist[j-1];
j--;
}
else break;
}
gRanklist[j]=temp;
}
} void MakeRank(int N)
{
int i;
gUserInfo[gRanklist[0]].rank=1;
for(i=1;i<N;i++)
{
if(gUserInfo[gRanklist[i]].totalScore==gUserInfo[gRanklist[i-1]].totalScore)
gUserInfo[gRanklist[i]].rank=gUserInfo[gRanklist[i-1]].rank;
else
gUserInfo[gRanklist[i]].rank=i+1;
}
} void CalcPointForSort(int N)
{
int i;
for(i=0;i<N;i++)
{
gUserInfo[i].pointForSort=gUserInfo[i].totalScore*10+gUserInfo[i].allClearCount;
}
} int main()
{
int i,j,N,K,M;
int ID,pID,score;
scanf("%d %d %d",&N,&K,&M);
InitSubmissions( N, K);
for(i=0;i<K;i++)
{
scanf("%d",&gProblemTable[i]);
}
for(i=0;i<M;i++)
{
scanf("%d %d %d",&ID,&pID,&score);
if(score!= -1)
gUserInfo[ID-1].eversubmitted=1;
else
score=0;
if(score>gSubmissions[ID-1][pID-1]) //只有比上一次大才处理,可以防止重复AC
{
gSubmissions[ID-1][pID-1]=score;
if(score==gProblemTable[pID-1])
gUserInfo[ID-1].allClearCount++;
}
}
CalcTotalScore(N,K); //计算每个用户总分
CalcPointForSort(N); //把分数x10然后加上ac次数作为排序依据
InitRanklist(); //初始化间接的排名表
IndriectInsertionSort(N); //排序
MakeRank(N); //计算每个用户的名次 for(i=0;i<N;i++)
{
if(gUserInfo[gRanklist[i]].eversubmitted==0)
continue;
printf("%d %05d %d",gUserInfo[gRanklist[i]].rank,gRanklist[i]+1,gUserInfo[gRanklist[i]].totalScore);
for(j=0;j<K;j++)
{
if(gSubmissions[gRanklist[i]][j]== UNSUBMITTED)
printf(" -");
else
printf(" %d",gSubmissions[gRanklist[i]][j]);
}
printf("\n");
} }

  

 

PTA 10-排序5 PAT Judge (25分)的更多相关文章

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

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

  2. PTA 5-15 PAT Judge (25分)

    /* * 1.主要就用了个sort对结构体的三级排序 */ #include "iostream" #include "algorithm" using nam ...

  3. PATA1075 PAT Judge (25 分)

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

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

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

  5. A1075 PAT Judge (25 分)

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

  6. 【PAT甲级】1075 PAT Judge (25 分)

    题意: 输入三个正整数N,K,M(N<=10000,K<=5,M<=100000),接着输入一行K个正整数表示该题满分,接着输入M行数据,每行包括学生的ID(五位整数1~N),题号和 ...

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

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

  8. PAT甲级:1025 PAT Ranking (25分)

    PAT甲级:1025 PAT Ranking (25分) 题干 Programming Ability Test (PAT) is organized by the College of Comput ...

  9. 1025 PAT Ranking (25分)

    1025 PAT Ranking (25分) 1. 题目 2. 思路 设置结构体, 先对每一个local排序,再整合后排序 3. 注意点 整体排序时注意如果分数相同的情况下还要按照编号排序 4. 代码 ...

随机推荐

  1. 终端工具Xmanager使用技巧

    1. 新建绘画使用终端连接服务器 2. 设置终端类型和编码 3. 设置终端外观,包括字体颜色等等 4. 设置默认上传路径和下载路径

  2. NBUT 1117 Kotiya's Incantation(字符输入处理)

    题意: 比较两个串,有三种情况:完全相同,可见字符相同,不同.每个字符串以'-'结尾.难点在输入. 思路: 字符逐个读入,直到'-'为止,读出两串就可以直接进行判断.如果不足两串则结束.输入时需要注意 ...

  3. 洛谷 P2068 统计和

    题目描述 给定一个长度为n(n<=100000),初始值都为0的序列,x(x<=10000)次的修改某些位置上的数字,每次加上一个数,然后提出y (y<=10000)个问题,求每段区 ...

  4. 在Mac里给Terminal终端自定义颜色

    Mac里终端显示默认是一种颜色,太单调了. 然而我们可以自定义这些颜色显示.进入-目录,编辑文件.bash_profile, 输入如下内容: 第三行那些fxfxax看起来是不是像天书?实际上是有规律的 ...

  5. strongSwan大坑一直重启(ubuntu)

    报错 Starting strongSwan 5.3.2 IPsec [starter]... charon (20533) started after 40 ms charon stopped af ...

  6. dp 20190618

    C. Party Lemonade 这个题目是贪心,开始我以为是背包,不过也不太好背包,因为这个L都已经是1e9了. 这个题目怎么贪心呢?它是因为这里有一个二倍的关系,所以说val[i]=val[i- ...

  7. Kruskal与Prim

    一.最小生成树 在无向图中,连通且不含圈的图称为树(Tree).给定无向图G=(V,E),连接G中所有点,且边集是E的子集的树称为G的生成树(Spanning Tree),而权值最小的生成树称为最小生 ...

  8. core 下使用 autofac

    依赖注入小伙伴们比较常了,这里只说core 下autofac依赖注入的使用 ,不多费话,直接代码. 在 Startup.cs里 public void ConfigureServices(IServi ...

  9. DP玄学优化——斜率优化

    --以此博客来悼念我在\(QBXT\)懵逼的时光 \(rqy\; tql\) (日常%\(rqy\)) 概念及用途 斜率优化是\(DP\)的一种较为常用的优化(据说在高中课本里稍有提及),它可以用于优 ...

  10. PAT 乙级 1009

    题目 题目地址:PAT 乙级 1009 题解 本题本身属于比较简单的字符串操作题,但是因为对于string的操作和函数不熟悉导致本题做起来很费劲,需要加强对于string类以及相关方法的理解和熟练程度 ...