08-排序6. PAT Judge (25)
2015-06-30 21:47
323 查看
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:
Sample Output:
提交代码
————————————————————
太多细节,自己都不敢看了,自己一直是19分,这里有两个测试用例无法通过,先放在这里。
上面的代码太乱了,太乱了,有时间得自己整理下。
下面的代码是http://blog.csdn.net/xyzchenzd/article/details/27074665的,看起来还不错的样子,先学习下。
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 -
提交代码
————————————————————
太多细节,自己都不敢看了,自己一直是19分,这里有两个测试用例无法通过,先放在这里。
#include <iostream> #include <stdlib.h> #include <vector> #include <algorithm> #include <memory.h> using namespace std; /* run this program using the console pauser or add your own getch, system("pause") or input loop */ #define NUM 10011 struct student { int user_id; int totalScore; int scores[6]; int rank; int perf; bool flag; }stu[NUM]; bool cmp(student a, student b) { if(a.totalScore != b.totalScore) { return a.totalScore>b.totalScore; } else { if(a.perf != b.perf) { return a.perf>b.perf; } else { return a.user_id<b.user_id; } } } int main(int argc, char** argv) { int N,K,M; // memset(stu,0,sizeof(stu)); cin>>N>>K>>M; int *p=(int *)malloc((K+1)*sizeof(int)); for(int i=1; i<=K; i++) { int tmp_score; cin>>tmp_score; *(p+i)=tmp_score; } for(int i=1; i<=N; i++)//³õʼ»¯ { stu[i].user_id=i; stu[i].perf=0; stu[i].totalScore=0; stu[i].rank=0; stu[i].flag=false; for(int j=1; j<=K; j++) stu[i].scores[j]=-2; } int usrid,pid,partialscore; for(int i=0; i<M; i++) { cin>>usrid>>pid>>partialscore; if(partialscore==-1) { if(stu[usrid].scores[pid]<partialscore) stu[usrid].scores[pid]=partialscore; continue; } else if(partialscore>=0)//±àÒëͨ¹ý£¬ÓÐµÃ·Ö { stu[usrid].flag=true; if(partialscore>stu[usrid].scores[pid]) { stu[usrid].scores[pid]=partialscore; } if(partialscore==p[pid])//Âú·Ö { ++stu[usrid].perf; } } } for(int i=1; i<=N; i++) { for(int j=1; j<=K; j++) { if(stu[i].scores[j]>0) { stu[i].totalScore+=stu[i].scores[j]; } } } sort(stu+1,stu+N+1,cmp); stu[1].rank=1; for(int i=2; i<=N; i++) { if(stu[i].totalScore==stu[i-1].totalScore) { stu[i].rank=stu[i-1].rank; } else { stu[i].rank=i; } } for(int i=1; i<=N; i++) { if(stu[i].totalScore!=0) { printf("%d %05d %d",stu[i].rank,stu[i].user_id,stu[i].totalScore); for(int j=1; j<=K; j++) { if(stu[i].scores[j]>=0) { printf(" %d",stu[i].scores[j]); } else if(stu[i].scores[j] == -1) { printf(" 0"); } else { printf(" -"); } } printf("\n"); } } return 0; }
上面的代码太乱了,太乱了,有时间得自己整理下。
下面的代码是http://blog.csdn.net/xyzchenzd/article/details/27074665的,看起来还不错的样子,先学习下。
#include <iostream> #include <cstdio> #include <vector> #include <algorithm> using namespace std; struct stu //学生结构 { int id; //id int s[5]; //各题分数,内部从0开始编号 int score; //总分 int pass; //完全正确题目数 int ns; //无提交或无任何通过编译标志,0代表没有通过 stu() //初始化 { id=0;score=0;pass=0;ns=0; for(int i=0;i<5;i++) s[i]=-2; //由于输出要求,对没有处理过的用-2表示 } }; bool cm(const stu &s1,const stu &s2); //比较 int main() { int n,k,m; cin>>n>>k>>m; stu *student=new stu ; //学生,标号i对应真实id-1 int p[5]; //分门分数 int i,j; for(i=0;i<k;i++) //输入信息 scanf("%d",&p[i]); int id,p_id,ps; for(i=0;i<m;i++) { scanf("%d %d %d",&id,&p_id,&ps); if(ps>student[id-1].s[p_id-1]) student[id-1].s[p_id-1]=ps; } for(i=0;i<n;i++) //计算总分,完全正确题目数,是否需要剔除 { student[i].id=i+1; for(j=0;j<k;j++) { if(student[i].s[j]>=0) { student[i].score+=student[i].s[j]; student[i].ns=1; } if(student[i].s[j]==p[j]) student[i].pass++; } } stable_sort(student,student+n,cm); //稳定排序,可以免去一次id比较 int rank=1; //当前的名次,处理并列用 int score=student[0].score; //当前的分数 for(i=0;i<n;i++) { if(student[i].ns==0) //到达无用数据段跳出 break; if(student[i].score!=score) //不是并列,刷新分数 { rank=i+1; score=student[i].score; } printf("%d %05d %d",rank,student[i].id,student[i].score); //输出信息 for(j=0;j<k;j++) { if(student[i].s[j]>=0) printf(" %d",student[i].s[j]); else if(student[i].s[j]==-1) printf(" 0"); else printf(" -"); } printf("\n"); } delete [] student; return 0; } bool cm(const stu &s1,const stu &s2) //按总分和完全正确题目数排序用比较 { if(s1.score>s2.score) return true; else if(s1.score==s2.score) return s1.pass>s2.pass; else return false; }
相关文章推荐
- 有向图欧拉回路 Codeforces508D Tanya and Password
- ubuntu-date命令的使用
- HTTP基础
- 解决acadia交叉编译后程序不能运行的问题。
- 开篇
- asp 之 让实体中字段类型为DateTime的字段只显示日期不显示时间
- IOS 启动画面设置
- 关于php/js抓取/采集
- itext 使用详解 02 - itext 基本模块
- 异常
- 脏读,不可重复读与幻读
- JS获取request的字符串变量,复选框的选中赋值
- 最常用的字
- 走进Struts2(四)— 自定义转换器
- 关于string的成员函数substr
- 如何正确使用tar命令
- 【Oracle错误集锦】:ORA-12154: TNS: 无法解析指定的连接标识符
- Android SDK和ADT无法更新的解决办法
- 知识整理回顾(一)
- libjpeg学习2:内存篇