PAT 1025 PAT Ranking
#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的更多相关文章
- 1025 PAT Ranking[排序][一般]
1025 PAT Ranking (25)(25 分) Programming Ability Test (PAT) is organized by the College of Computer S ...
- PAT 甲级 1025 PAT Ranking
1025. PAT Ranking (25) 时间限制 200 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Programmi ...
- 1025 PAT Ranking (25分)
1025 PAT Ranking (25分) 1. 题目 2. 思路 设置结构体, 先对每一个local排序,再整合后排序 3. 注意点 整体排序时注意如果分数相同的情况下还要按照编号排序 4. 代码 ...
- PAT甲级——1025 PAT Ranking
1025 PAT Ranking Programming Ability Test (PAT) is organized by the College of Computer Science and ...
- PAT甲级:1025 PAT Ranking (25分)
PAT甲级:1025 PAT Ranking (25分) 题干 Programming Ability Test (PAT) is organized by the College of Comput ...
- 浙大pat 1025题解
1025. PAT Ranking (25) 时间限制 200 ms 内存限制 32000 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Programmi ...
- PAT A1141 PAT Ranking of Institutions (25 分)——排序,结构体初始化
After each PAT, the PAT Center will announce the ranking of institutions based on their students' pe ...
- [PAT] 1141 PAT Ranking of Institutions(25 分)
After each PAT, the PAT Center will announce the ranking of institutions based on their students' pe ...
- PAT 1141 PAT Ranking of Institutions
After each PAT, the PAT Center will announce the ranking of institutions based on their students' pe ...
随机推荐
- CF165D Beard Graph
$ \color{#0066ff}{ 题目描述 }$ 给定一棵树,有m次操作. 1 x 把第x条边染成黑色 2 x 把第x条边染成白色 3 x y 查询x~y之间的黑边数,存在白边输出-1 \(\co ...
- select 插入数据 不自增列实现自增
- JUC包下CountDownLatch学习笔记
CountDownLatch的作用是能使用多个线程进来之后,且线程任务执行完毕之后,才执行, 闭锁(Latch):一种同步方法,可以延迟线程的进度直到线程到达某个终点状态.通俗的讲就是,一个闭锁相当于 ...
- mysql 彻底解决:Incorrect string value: '\xF0\x9F\x98\xAD",...' for column 'commentContent' at row 1
彻底解决:Incorrect string value: '\xF0\x9F\x98\xAD",...' for column 'commentContent' at row 1 今天在爬取 ...
- Python循环流程
1.for循环 计算1+2+3+……+100的和 count = 0 i = 1 for i in range(101): count+=i print(count) 前n项和公式为:Sn=n*a1+ ...
- Idea 软件使用快捷键归纳
<1>CTRL+P 方法参数提示 <2>ctrl+/ 单行注释 <3>Ctrl+Alt+M IDEA 重复代码快速重构(抽取重复代码快捷键) <4> ...
- POJ_2407 Relatives 【欧拉函数裸题】
一.题目 Given n, a positive integer, how many positive integers less than n are relatively prime to n? ...
- 求一个区间里的一个x,这个x与这区间里面的所有数都互质
链接:https://ac.nowcoder.com/acm/contest/301/H来源:牛客网 题描述 小乐乐上了一节数学课,数学老师讲的很好,小乐乐听的也如痴如醉. 小乐乐听了老师的讲解,知道 ...
- 从源码角度深入分析 ant
[转自] http://www.tuicool.com/articles/eQvIRbA Ant的基本概念 首先是ant的基本概念: Project,Target,Tasks,Properties,P ...
- 转 .net 获取IP地址的三个方法的比较
获取用户IP地址的三个属性的区别(HTTP_X_FORWARDED_FOR,HTTP_VIA,REMOTE_ADDR) 一.没有使用代理服务器的情况: REMOTE_ADDR = 您的 IP ...