#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. Tomcat类加载机制触发的Too many open files问题分析(转)

    https://blog.csdn.net/ctrip_tech/article/details/53337137 说起Too many open files这个报错,想必大家一定不陌生.在Linux ...

  2. 删除outlook2007账户

    开始-设置-控制面板-邮件-显示配置文件-删除-确定

  3. 【Linux】DNS服务-BIND基础配置

    1.BIND简介 现在使用最为广泛的DNS服务器软件是BIND(Berkeley Internet Name Domain),最早有伯克利大学的一名学生编写,现在最新的版本是9,有ISC(Intern ...

  4. [PowerShell]HTML parsing -- get information from a website

    link: http://stackoverflow.com/questions/9053573/powershell-html-parsing-get-information-from-a-webs ...

  5. Python循环流程

    1.for循环 计算1+2+3+……+100的和 count = 0 i = 1 for i in range(101): count+=i print(count) 前n项和公式为:Sn=n*a1+ ...

  6. C++_类和动态内存分配3-构造函数中使用new的注意事项

    如果在构造函数中使用new来初始化对象的指针成员时必须特别小心. 1 如果在构造函数中使用new来初始化指针成员,则应在析构函数中使用delete. 2 new和delete必须相互兼容.new对应于 ...

  7. Python-list()之remove()/pop() I /del()

    代码块 remove #remove删除首个符合条件的元素,并不删除特定的索引. n =[1,2,2,3,4,5] n.remove(3) print (n) #输出 [1, 2, 2, 4, 5] ...

  8. Autofac构建

    1.初始化 using System.Reflection; using System.Web; using System.Web.Mvc; using System.Configuration; u ...

  9. C# Autofac 的 BeanFactory

    using Autofac; using Microsoft.Practices.ServiceLocation; namespace Core.Common { /// <summary> ...

  10. flask综合案例

    一.项目准备 1.新建项目目录students,并创建虚拟环境 mkvirtualenv students 2.安装依赖环境 pip install flask==0.12.4 pip install ...