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 ...
随机推荐
- 浏览器HTTP_USER_AGENT汇总——Firefox、Chrome、IE9、IE8、IE7、IE6
结论: 浏览器 \ OS XP(IE6) XP(IE7) XP(IE8) Win7 x64(IE9) 猎豹浏览器2.0急速模式 Chrome/21 猎豹浏览器2.0兼容模式 IE6 ...
- 条目七《如果容器中包含了通过new操作创建的指针,切记在容器对象析构前将指针delete掉》
如果容器中包含了通过new操作创建的指针,切记在容器对象析构前将指针delete掉 在STL中容器是智能的,可以在容器销毁时自动调用容器里对象的析构函数来销毁容器存储的对象. STL的容器虽然比较智能 ...
- Linux系统管理之硬盘管理
硬盘是计算的重要组成部件之一,硬盘为操作系统提供持久话存储的功能,在Linux硬盘设备的性能和好坏可能关系到生成线的安全和用户体验等等.熟练的掌握硬盘管理相关的信息能让我们处理起这些问题来得心应手. ...
- WPF优化:Freezable冻结对象
原文:WPF优化:Freezable冻结对象 WPF虽然很美观,效果很炫,但是对资源的消耗也很大,尤其是初次接触WPF的人,因为很多地方虽然实现了想要的效果,但是由于经验问题,所以也会造成很大的资源浪 ...
- 【算法笔记】B1013 数素数
1013 数素数 (20 分) 令 Pi 表示第 i 个素数.现任给两个正整数 M≤N≤104,请输出 PM 到 PN 的所有素数. 输入格式: 输入在一行中给出 M 和 N, ...
- C# 关于utf-8的研究
前提 如果一不小心把字符转成utf8的格式,但是却产生了乱码.这个时候要么就是寻找其他的转码方式,要么就不想要了,直接过滤吧. 这里说的是直接过滤的办法. 参考链接 https://netvignet ...
- Filezilla 错误
一般来说,只要网站能访问,FTP就应该能连接的,之前好长一段时间一直遇到连接不上香港主机的问题,还以为是宽带出口线路不好,原来是自己学识浅薄,在同事的指点下才明白所以然,下面总结一下FTP连接中的常见 ...
- 小a的计算器
链接:https://ac.nowcoder.com/acm/contest/317/A来源:牛客网 小a的数学基础实在太差了,以至于他只会用计算器算数.他的计算器比较特殊,只有+,−,×,/+,−, ...
- 获取各站点的ID
using (var serverManager = new ServerManager()) { foreach(var site in serverManager.Sites) { Console ...
- PIE SDK存储格式转换
1.算法功能简介 影像存储格式转换可以实现栅格数据存储格式的自由转换,其中存储格式可以是 BSQ. BIP. BIL 三种格式. 遥感数字图像数据的存储与分发,通常采用以下三种数据格式: BSQ( ...