排序,求整体的排名和局部的排名
整体排序,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)-排序的更多相关文章

  1. PAT甲题题解-1129. Recommendation System (25)-排序

    博主欢迎转载,但请给出本文链接,我尊重你,你尊重我,谢谢~http://www.cnblogs.com/chenxiwenruo/p/6789819.html特别不喜欢那些随便转载别人的原创文章又不给 ...

  2. PAT甲题题解-1051. Pop Sequence (25)-堆栈

    将1~n压入最多为m元素的栈 给出k个出栈序列,问你是否能够实现. 能输出YES 否则NO 模拟一遍即可,水题. #include <iostream> #include <cstd ...

  3. PAT甲题题解-1059. Prime Factors (25)-素数筛选法

    用素数筛选法即可. 范围long int,其实大小范围和int一样,一开始以为是指long long,想这就麻烦了该怎么弄. 而现在其实就是int的范围,那难度档次就不一样了,瞬间变成水题一枚,因为i ...

  4. PAT甲题题解-1075. PAT Judge (25)-排序

    相当于是模拟OJ评测,这里注意最后输出:1.那些所有提交结果都是-1的(即均未通过编译器的),或者从没有一次提交过的用户,不需要输出.2.提交结果为-1的题目,最后输出分数是03.某个题目从没有提交过 ...

  5. PAT甲题题解-1101. Quick Sort (25)-大水题

    快速排序有一个特点,就是在排序过程中,我们会从序列找一个pivot,它前面的都小于它,它后面的都大于它.题目给你n个数的序列,让你找出适合这个序列的pivot有多少个并且输出来. 大水题,正循环和倒着 ...

  6. PAT甲题题解-1117. Eddington Number(25)-(大么个大水题~)

    如题,大水题...贴个代码完事,就这么任性~~ #include <iostream> #include <cstdio> #include <algorithm> ...

  7. PAT甲题题解-1130. Infix Expression (25)-中序遍历

    博主欢迎转载,但请给出本文链接,我尊重你,你尊重我,谢谢~http://www.cnblogs.com/chenxiwenruo/p/6789828.html特别不喜欢那些随便转载别人的原创文章又不给 ...

  8. PAT甲题题解-1016. Phone Bills (25)-模拟、排序

    博主欢迎转载,但请给出本文链接,我尊重你,你尊重我,谢谢~http://www.cnblogs.com/chenxiwenruo/p/6789229.html特别不喜欢那些随便转载别人的原创文章又不给 ...

  9. PAT甲题题解-1021. Deepest Root (25)-dfs+并查集

    dfs求最大层数并查集求连通个数 #include <iostream> #include <cstdio> #include <algorithm> #inclu ...

随机推荐

  1. Azure DevKit(AZ3166)源码找不到头文件问题

    Get “Error Presented: #include errors detected” when opening a project The error message is Error Pr ...

  2. Django商城项目笔记No.10用户部分-登录接口

    Django商城项目笔记No.10用户部分-登录接口 添加url路由 接下来第二步,增加返回内容: 增加结果如下: 配置:上边的方法定义了返回的内容都有哪些,那这个方法jwt还不知道,需要配置: 修改 ...

  3. 分享-结合demo讲解JS引擎工作原理

    代码如下: var x = 1; function A(y){ var x = 2; function B(z){ console.log(x+y+z); } return B; } var C = ...

  4. 2-5 R语言基础 factor

    #因子:分类数据#有序和无序#整数向量+标签label#Male/Female#常用于lm(),glm() > x <- factor(c("female"," ...

  5. pytorch代码资源

    pytorch版本的faster和fpn https://github.com/jwyang/faster-rcnn.pytorch https://github.com/jwyang/fpn.pyt ...

  6. calico 排错记录 apt-get install telnet

    1.用kubespray部署一个单节点集群,kubectl get pods -n kube-system,结果: calico-node-7v8wx 1/1 Running 0 2dcalico-n ...

  7. python 爬虫--同花顺-使用代理

    1.http://www.goubanjia.com/  在上面获取 使用http协议的公网IP和端口 参考:https://blog.csdn.net/qq_23934063/article/det ...

  8. day47

    高级布局 一.文档流(normal flow) 1.概念 本质为normal flow(普通流.常规流)将窗体自上而下分成一行一行,块级元素从上至下.行内元素在每行中从左至右的顺序依次排放元素. v_ ...

  9. jqgrid 配置行号及行号的宽度

    有时,我们想把jqgrid的行号按指定的宽度显示出来,如何实现? 通过 rownumbers:true  设置启用行号 通过 rownumWidth 配置行号列的宽度 $("#jqGrid& ...

  10. spring-boot dubbo项目使用docker方式部署

    项目结构 本项目采用maven构建,有三个模块,分别是pms-interfaces, pms-services, pms-portal. 模块 描述 pms-interfaces 接口层,只能存放实体 ...