PAT甲题题解-1025. PAT Ranking (25)-排序
排序,求整体的排名和局部的排名
整体排序,for循环一遍
同时存储整体目前的排名和所在局部的排名即可
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string.h>
#include <cmath>
#include <queue>
#include <map>
using namespace std;
const int maxn=;
const int maxk=;
int local_Rank[maxn]; //local_Rank[i]表示第i个组目前的排名
int last_local_id[maxn]; //last_local_id[i]表示第i个组前一个在整体中的索引
struct Node{
long long id;
int score;
int group;
int ranks;
int local_rank;
bool operator<(const Node tmp)const{
if(score==tmp.score)
return id<tmp.id;
else
return score>tmp.score;
}
}stu[maxn*maxk];
int main()
{
int n,k;
scanf("%d",&n);
int cnt=;
long long id;
int score;
for(int i=;i<=n;i++){
scanf("%d",&k);
for(int j=;j<k;j++){
scanf("%lld %d",&id,&score);
stu[cnt].id=id;
stu[cnt].score=score;
stu[cnt].group=i;
cnt++;
}
}
printf("%d\n",cnt);
sort(stu,stu+cnt);
memset(local_Rank,,sizeof(local_Rank));
int global_rank=; //整体排名
for(int i=;i<cnt;i++){
if(global_rank==){
stu[i].ranks=;
global_rank=;
}
else{
if(stu[i].score==stu[i-].score){
stu[i].ranks=stu[i-].ranks;
global_rank++;
}
else{
global_rank++;
stu[i].ranks=global_rank;
}
}
int group=stu[i].group;
if(local_Rank[group]==){
stu[i].local_rank=;
local_Rank[group]=;
last_local_id[group]=i;
}
else{
int id=last_local_id[group];
if(stu[i].score==stu[id].score){
stu[i].local_rank=stu[id].local_rank;
local_Rank[group]++;
}
else{
local_Rank[group]++;
stu[i].local_rank=local_Rank[group];
last_local_id[group]=i;
}
}
printf("%013lld %d %d %d\n",stu[i].id,stu[i].ranks,stu[i].group,stu[i].local_rank);
}
return ;
}
PAT甲题题解-1025. PAT Ranking (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甲题题解-1075. PAT Judge (25)-排序
相当于是模拟OJ评测,这里注意最后输出:1.那些所有提交结果都是-1的(即均未通过编译器的),或者从没有一次提交过的用户,不需要输出.2.提交结果为-1的题目,最后输出分数是03.某个题目从没有提交过 ...
- 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 ...
随机推荐
- Alpha冲刺报告(8/12)(麻瓜制造者)
今日已完成 邓弘立: 完成了对主页UI控件的更新 符天愉: 没有完成留言模块,只是完成了留言的查询并且将留言多级回复格式化,同时和队友一起部署了商品发布的接口 江郑: 经过了这几天的编码,需求方面的数 ...
- SVN 图标不显示的解决办法
SVN 的图标没办法显示了.经搜索,发现需要修改注册表 HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Sh ...
- mpvue 应用 Vant Weapp框架开发微信小程序
今天在使用mpvue开发微信小程序的过程中需要实现一个底部上拉选择列表的功能,因为之前做过H5微信公众号的开发,使用的就是有赞的Vant-ui,所以第一时间就想到了有赞的Vant Weapp UI框架 ...
- Windows连接Linux虚拟机里面的Docker容器
一.Windows.Linux虚拟机.docker关系图 如果此时在Windows宿主机中pingDocker容器是ping不同的,因为在宿主机上没有通往172.17.0.0/24网络的路由,宿主机会 ...
- java读写properties配置文件方法
1.Properties类 Properties类表示了一个持久的属性集.Properties可保存在流中或从流中加载,属性列表中的key和value必须是字符串. 虽然Properties类继承了j ...
- opencv——对象提取与测量
#include <opencv2/opencv.hpp> #include <iostream> #include <math.h> using namespac ...
- J-Link调试查看变量值总是显示<not in scope> 和<cannot evaluate>问题
原文:https://blog.csdn.net/gmpy_tiger/article/details/50395719 MDK/Keil 中,J-Link调试查看变量值总是显示<not in ...
- leetcode63—Unique Path II
A robot is located at the top-left corner of a m x n grid (marked 'Start' in the diagram below). The ...
- js 对于jquery each 多层循环的问题和原生js多层循环问题
一.在jquery中,我们使用循环的时候,提供两种方式:jquery.each 和(循环体).each 两种方式不是同. 对于return 在作用这两个的函数的时候需要注意: 首先我们需要知道我们的 ...
- python获取文件扩展名的方法(转)
主要介绍了python获取文件扩展名的方法,涉及Python针对文件路径的相关操作技巧.具体实现方法如下: 1 2 3 4 import os.path def file_extension(path ...