#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. redis源码分析(3)sds

    sds是redis中用来处理字符串的数据结构.sds的定义在sds.h中: typedef char *sds; 简洁明了!简明扼要!(X,玩我呢是吧!这特么不就是c中的字符串么?!).像redis这 ...

  2. networkx如何将图写到邻接矩阵里?

    nx.write_adjlist(G1,graph_filename1)#生成的是二进制文件nx.write_adjlist(G2,graph_filename2)

  3. 魔方方法之--类的构造(__init__,__new__)和析构(__del__)方法

    构造方法(参见小甲鱼入门教程) __ init__()方法:类的初始化方法,初始化类对象时被调用,需要的时候再调用它 注意点:这个方法的返回值必须是None class Rectangle(): de ...

  4. js去重方法

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

  5. 模板【洛谷P3368】 【模板】树状数组 2

    P3368 [模板]树状数组 2 如题,已知一个数列,你需要进行下面两种操作: 1.将某区间每一个数数加上x 2.求出某一个数的值 树状数组区间加,单点查询. code: #include <i ...

  6. [SCOI2009]windy数 BZOJ1026 数位dp

    题目描述 windy定义了一种windy数.不含前导零且相邻两个数字之差至少为2的正整数被称为windy数. windy想知道, 在A和B之间,包括A和B,总共有多少个windy数? 输入输出格式 输 ...

  7. C++_类和动态内存分配2-改进后的String类

    添加前面介绍过的复制构造函数和赋值运算符,使类能够正确管理类对象使用的内存. 知道对象何时被创建和释放. =================================== 修订后的默认构造函数 ...

  8. Applese 的QQ群(二分+dfs)

    链接:https://ac.nowcoder.com/acm/contest/330/F 来源:牛客网 时间限制:C/C++ 2秒,其他语言4秒 空间限制:C/C++ 262144K,其他语言5242 ...

  9. 详解Oracle hints PQ_DISTRIBUTE

    PQ_DISTRIBUTE是并行的hints中稍微复杂一点的一个 下面就这个hints做以下说明: 1.使用格式 /+ PQ_DISTRIBUTE(tablespec outer_distributi ...

  10. 《STL详解》解题报告

    看完发现文档缺页...... 3.5  菲波那契数 vector<int> v; v.push_back(); v.push_back(); ;i < ;++i) v.push_ba ...