PAT甲题题解-1075. PAT Judge (25)-排序
相当于是模拟OJ评测,这里注意最后输出:
1.那些所有提交结果都是-1的(即均未通过编译器的),或者从没有一次提交过的用户,不需要输出。
2.提交结果为-1的题目,最后输出分数是0
3.某个题目从没有提交过的,输出'-'
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string.h>
#include <cmath>
#include <queue>
#define INF 0x3f3f3f3f
using namespace std;
const int maxn=+;
int problem[]; struct User{
int id;
int score=;
int problem[]={-,-,-,-,-,-};
int submitted[]={,,,,,}; //标记题目是否有提交,没提交的对应的就要输出'-'
int perfect=; //拿满分的题目个数
int ranks=INF;
int isShow=; //用于标记是否要输出,即用户只要有一题通过编译器,不管是否为0,设置为1.
bool operator<(const User tmp)const{
if(ranks==tmp.ranks){
if(perfect==tmp.perfect){
return id<tmp.id;
}
else{
return perfect>tmp.perfect;
}
}
else{
return ranks<tmp.ranks;
}
}
}user[maxn]; bool cmp1(User a, User b){
return a.score>b.score;
} bool cmp2(User a,User b){
if(a.ranks==b.ranks){
if(a.perfect==b.perfect){
return a.id<b.id;
}
else{
return a.perfect>b.perfect;
}
}
else{
return a.ranks<b.ranks;
}
} int main()
{
int N,K,M;
int id,pid,score;
scanf("%d %d %d",&N,&K,&M);
for(int i=;i<=K;i++){
scanf("%d",&problem[i]);
}
for(int i=;i<M;i++){
scanf("%d %d %d",&id,&pid,&score);
user[id].id=id;
user[id].problem[pid]=max(user[id].problem[pid],score);
user[id].submitted[pid]=;
//if(score==problem[pid])
// user[id].perfect++; //不能这里就统计拿满分的题目个数,因为可能存在多次提交
if(score!=-)
user[id].isShow=;
}
for(int i=;i<=N;i++){
for(int j=;j<=K;j++){
if(user[i].problem[j]!=-)
user[i].score+=user[i].problem[j];
if(user[i].problem[j]==problem[j])
user[i].perfect++;
}
}
sort(user+,user+N+,cmp1); int cnt=;
int lastid=;
user[].ranks=cnt;
user[].score=-;
for(int i=;i<=N;i++){
user[i].ranks=i;
if(i!= && user[i].score==user[i-].score)
user[i].ranks=user[i-].ranks;
}
sort(user+,user+N+,cmp2);
for(int i=;i<=N;i++){
if(user[i].isShow==)
continue;
printf("%d %05d %d",user[i].ranks,user[i].id,user[i].score);
for(int j=;j<=K;j++){
if(user[i].submitted[j]==){
printf(" -");
}
else{
if(user[i].problem[j]!=-)
printf(" %d",user[i].problem[j]);
else
printf("");
}
}
printf("\n");
}
return ;
}
PAT甲题题解-1075. PAT Judge (25)-排序的更多相关文章
- PAT甲题题解-1129. Recommendation System (25)-排序
博主欢迎转载,但请给出本文链接,我尊重你,你尊重我,谢谢~http://www.cnblogs.com/chenxiwenruo/p/6789819.html特别不喜欢那些随便转载别人的原创文章又不给 ...
- PAT甲题题解-1051. Pop Sequence (25)-堆栈
将1~n压入最多为m元素的栈 给出k个出栈序列,问你是否能够实现. 能输出YES 否则NO 模拟一遍即可,水题. #include <iostream> #include <cstd ...
- PAT甲题题解-1059. Prime Factors (25)-素数筛选法
用素数筛选法即可. 范围long int,其实大小范围和int一样,一开始以为是指long long,想这就麻烦了该怎么弄. 而现在其实就是int的范围,那难度档次就不一样了,瞬间变成水题一枚,因为i ...
- PAT甲题题解-1101. Quick Sort (25)-大水题
快速排序有一个特点,就是在排序过程中,我们会从序列找一个pivot,它前面的都小于它,它后面的都大于它.题目给你n个数的序列,让你找出适合这个序列的pivot有多少个并且输出来. 大水题,正循环和倒着 ...
- PAT甲题题解-1117. Eddington Number(25)-(大么个大水题~)
如题,大水题...贴个代码完事,就这么任性~~ #include <iostream> #include <cstdio> #include <algorithm> ...
- PAT甲题题解-1130. Infix Expression (25)-中序遍历
博主欢迎转载,但请给出本文链接,我尊重你,你尊重我,谢谢~http://www.cnblogs.com/chenxiwenruo/p/6789828.html特别不喜欢那些随便转载别人的原创文章又不给 ...
- PAT甲题题解-1016. Phone Bills (25)-模拟、排序
博主欢迎转载,但请给出本文链接,我尊重你,你尊重我,谢谢~http://www.cnblogs.com/chenxiwenruo/p/6789229.html特别不喜欢那些随便转载别人的原创文章又不给 ...
- PAT甲题题解-1021. Deepest Root (25)-dfs+并查集
dfs求最大层数并查集求连通个数 #include <iostream> #include <cstdio> #include <algorithm> #inclu ...
- PAT甲题题解-1024. Palindromic Number (25)-大数运算
大数据加法给一个数num和最大迭代数k每次num=num+num的倒序,判断此时的num是否是回文数字,是则输出此时的数字和迭代次数如果k次结束还没找到回文数字,输出此时的数字和k 如果num一开始是 ...
随机推荐
- You are not late! You are not early!
Do you think you are going No Where in Life? STOP! Take a deep breathe THINK! New York is three hour ...
- Javaweb学习(三):Servlet程序
好了,既然开发环境已经配置好了.那么我们首先要搞定得便是servlet了,至于为什么不先去研究jsp,这是因为jsp与servlet本就是一体两面,jsp其本身经过编译.载入.转化等步骤最终会成为se ...
- November 10th, 2017 Week 45th Friday
A little bit of mercy makes the world less cold and more just. 多一点怜悯就可以让这个世界少一点冷酷而多一点正义. Maybe there ...
- October 27th, 2017 Week 43rd Friday
The only thing predictable about life is its unpredictability. 人生唯一可以预知的,就是它的变化莫测. Is it really unpr ...
- sourceTree跳过注册
sourceTree是一个很方便的git管理工具,但是现在一直无法注册,本文记录了跳过注册的方法. 将下面的代码赋值到地址栏 %LocalAppData%\Atlassian\SourceTree\ ...
- python第二十九课——文件读写(读取读取中文字符)
演示:读取中文字符 结论: 1).如果不设置encoding,默认使用gbk进行编解码 2).如果编码和解码不一致,最终导致报错,但是一旦设置了errors='ingore',那么就不会报错,而采取乱 ...
- BZOJ2306:[CTSC2011]幸福路径(倍增Floyd)
Description 有向图 G有n个顶点 1, 2, …, n,点i 的权值为 w(i).现在有一只蚂蚁,从给定的起点 v0出发,沿着图 G 的边爬行.开始时,它的体力为 1.每爬过一条边,它 ...
- jQuery 使用ajax,并刷新页面
<script> function del_product_information(id) { $.ajax({ url: "{% url 'del_product_inform ...
- 选择当天一周一月导出excel表格
<a href="javascript:;" class="fr btn btn-primary radius mt-6 mr-10" onclick=& ...
- php请求API接口方法
thinkphp下直接放入公共函数即可. /** * 通过URL获取页面信息 * @param string $url 地址 * @return string 返回页面信息 */ function g ...