#include <cstdio>
#include <cstdlib>
#include <vector>
#include <cstring>
#include <queue>
#include <algorithm> using namespace std; class Man {
public:
char id[];
int location;
int score;
int local_rank;
}; class RankCmp{
public:
bool operator () (const Man* a, const Man* b) {
if (a->score > b->score) {
return true;
} else if (a->score < b->score) {
return false;
} return strcmp(a->id, b->id) < ;
}
}; void do_local_rank(vector<Man*> &v) {
int len = v.size();
if (len < ) return; int last_score = v[]->score;
v[]->local_rank = ; for (int i=; i<len; i++) {
Man& cur = *v[i];
if (cur.score != last_score) {
cur.local_rank = i + ;
last_score = cur.score;
} else {
cur.local_rank = v[i - ]->local_rank;
}
}
} void print(vector<Man*> &v) {
int len = v.size();
for (int i=; i<len; i++) {
printf("%s %d %d\n", v[i]->id, v[i]->score, v[i]->local_rank);
}
} int main() {
int N, K, total = ;
scanf("%d", &N);
vector<vector<Man*> > locations(N);
Man tmp; RankCmp rankcmp; for (int i=; i<N; i++) {
scanf("%d", &K);
for (int j=; j<K; j++) {
total++;
scanf("%s%d", tmp.id, &(tmp.score));
tmp.location = i + ;
locations[i].push_back(new Man(tmp));
}
sort(locations[i].begin(), locations[i].end(), rankcmp);
do_local_rank(locations[i]);
} printf("%d\n", total); vector<Man*> all; for (int i=; i<N; i++) {
all.insert(all.end(), locations[i].begin(), locations[i].end());
} sort(all.begin(), all.end(), rankcmp); int last_rank = , last_score = -;
for (int i=; i<total; i++) {
Man& cur = *all[i];
if (cur.score != last_score) {
last_score = cur.score;
last_rank = i + ;
}
printf("%s %d %d %d\n", cur.id, last_rank, cur.location, cur.local_rank);
}
return ;
}

最后一个全局排序300 * 100 log(300 * 100),如果用优先队列可以变为300 * 100 log(100),提升也不大,可能还是出现下降

PAT 1025 PAT Ranking的更多相关文章

  1. 1025 PAT Ranking[排序][一般]

    1025 PAT Ranking (25)(25 分) Programming Ability Test (PAT) is organized by the College of Computer S ...

  2. PAT 甲级 1025 PAT Ranking

    1025. PAT Ranking (25) 时间限制 200 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Programmi ...

  3. 1025 PAT Ranking (25分)

    1025 PAT Ranking (25分) 1. 题目 2. 思路 设置结构体, 先对每一个local排序,再整合后排序 3. 注意点 整体排序时注意如果分数相同的情况下还要按照编号排序 4. 代码 ...

  4. PAT甲级——1025 PAT Ranking

    1025 PAT Ranking Programming Ability Test (PAT) is organized by the College of Computer Science and ...

  5. PAT甲级:1025 PAT Ranking (25分)

    PAT甲级:1025 PAT Ranking (25分) 题干 Programming Ability Test (PAT) is organized by the College of Comput ...

  6. 浙大pat 1025题解

    1025. PAT Ranking (25) 时间限制 200 ms 内存限制 32000 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Programmi ...

  7. PAT A1141 PAT Ranking of Institutions (25 分)——排序,结构体初始化

    After each PAT, the PAT Center will announce the ranking of institutions based on their students' pe ...

  8. [PAT] 1141 PAT Ranking of Institutions(25 分)

    After each PAT, the PAT Center will announce the ranking of institutions based on their students' pe ...

  9. PAT 1141 PAT Ranking of Institutions

    After each PAT, the PAT Center will announce the ranking of institutions based on their students' pe ...

随机推荐

  1. The server of Apache (二)——apache服务客户端验证

    一.确定网站名称.IP地址 地址为: 192.168.1.1   域名为: www.benet.com 二.配置可用的DNS域名服务或者修改本地hosts记录 ~] # vim /etc/hosts ...

  2. 1. UML统一建模语言

    (1)UML概述: 建模: 对现实系统进行适当的过滤, 用适当的表现规则描述出简洁的模型. 建模是一种深入解决问题的方法. UML: UML(United Modeling Language, 统一建 ...

  3. Hibernate的工作流程以及三种状态

    Hibernate的工作流程: 1. 读取并解析配置文件 2.读取并解析映射信息,创建SessionFactory 3. 打开Sesssion 4.创建事务Transation 5. 持久化操作 6. ...

  4. js去重方法

    function remove(array){ var obj={}; newarray=[]; for(var i in array){ console.log(i); var arg=array[ ...

  5. 深入解析Close()和Dispose()的区别

    很多人都认为Close()方法内部会调用Dispose()方法,所以并没有本质的区别!实际上这个看法不是很准确,对有 些类来说,的确Close()和Dispose()没有本质区别,但是对有些类来说并非 ...

  6. POJ1358 Agri-Net

    题目链接 就是裸的最小生成树,复习一下. prim算法: G=(V,E),V是点集,E是边集 假设T=(U,TE)是最小生成树.U,TE初始化为空 首先从V中任取一点 假设取V1,然后U={V1},只 ...

  7. PHP将数据库数据批量生成word文档

    <?php    class word{         function start(){            ob_start();            echo '<html x ...

  8. grafana使用小节

    安装准备 安装grafana 安装mysql grafana操作步骤 新建数据源,支持mysql 数据库连接失败处理: https://www.jianshu.com/p/684bc3a77ac9 新 ...

  9. hdu1711 Number Sequence kmp模板

    题目传送门 学习博客 学习了kmp算法,理解了算法思想,但还没有到能把这个思想用语言来描述出来. #include<bits/stdc++.h> #define clr(a,b) mems ...

  10. dataTable 加了竖向滚动条导致列头样式错位的问题 / 亲测可用,不好用你打我,用好了记得点推荐

    tab在没有显示之前,容器是没有高度宽度的,而dt在自动计算高度和宽度时是获取的外部容器的高度和宽度,当切换tab时,dt获取不到这个高度宽度,导致列头都挤在一起,是用下面代码解决此问题 $('a[d ...