排序,求整体的排名和局部的排名
整体排序,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. MSChart 设置饼图颜色 图例背景色 图例显示位置

    chartField.Series.Clear();            chartField.ChartAreas.Clear();            chartField.Legends.C ...

  2. css常见的概念

    padding-top:10px;是指容器内的内容距离容器的顶部有10个像素,是包含在容器内的: margin-top:10px;是指容器本身的顶部距离其他容器有10个像素,不包含在容器内: top: ...

  3. php 错误1

    Maximum execution time of 30 seconds exceeded 方法一,修改php.ini文件 max_execution_time = 30; Maximum execu ...

  4. [翻译] 提升树算法的介绍(Introduction to Boosted Trees)

    [翻译] 提升树算法的介绍(Introduction to Boosted Trees) 1. 有监督学习的要素 XGBoost 适用于有监督学习问题.在此类问题中,我们使用多特征的训练数据集 \(x ...

  5. 启动android monitor报错解决办法

    再这汇总一下这段时间使用android monitor新遇到的问题,特汇总对应问题解决办法如下: 1.确保JDK和Android studio位数相同,比如JDK使用的是64位,studio也要是64 ...

  6. CompletionService简讲

    背景 最近在项目中看到太多后台task中使用Executor框架,提交任务后,把future都一个个加入到list,再一个个get这些future的代码. 这个的问题在于一方面没有时限,可能会被某些运 ...

  7. Moleskine智能笔+专用本:写完随时传到手机

    http://www.totiot.com/61805.html Moleskine公司生产的速写本和速写板一直是涂鸦爱好者和速记员们的首选.该公司还联合Adobe. Livescribe. Ever ...

  8. 1、JUC--volatile 关键字-内存可见性

    Java JUC简介 在 Java 5.0 提供了 java.util.concurrent (简称JUC )包,在此包中增加了在并发编程中很常用的实用工具类,用于定义类似于线程的自定义子系统,包括线 ...

  9. day2-课堂笔记

    #面向对象 函数=方法 系统内建函数:len().id() 对象函数

  10. VC++环境下单文档SDI与OpenGL多视图分割窗口的实现-类似3DMAX的主界面

    本文主要讲述如何在VC++环境下实现单文档SDI与OpenGL多视图分割窗口,最终的界面类似3DMAX的主界面.首先给出我实现的效果图: 整个实现过程网络上有很多零散的博文,请各位自行搜索,在基于对话 ...