PAT甲级:1025 PAT Ranking (25分)
PAT甲级:1025 PAT Ranking (25分)
题干
Programming Ability Test (PAT) is organized by the College of Computer Science and Technology of Zhejiang University. Each test is supposed to run simultaneously in several places, and the ranklists will be merged immediately after the test. Now it is your job to write a program to correctly merge all the ranklists and generate the final rank.
Input Specification:
Each input file contains one test case. For each case, the first line contains a positive number N (≤100), the number of test locations. Then N ranklists follow, each starts with a line containing a positive integer K (≤300), the number of testees, and then K lines containing the registration number (a 13-digit number) and the total score of each testee. All the numbers in a line are separated by a space.
Output Specification:
For each test case, first print in one line the total number of testees. Then print the final ranklist in the following format:
registration_number final_rank location_number local_rank
The locations are numbered from 1 to N. The output must be sorted in nondecreasing order of the final ranks. The testees with the same score must have the same rank, and the output must be sorted in nondecreasing order of their registration numbers.
Sample Input:
2
5
1234567890001 95
1234567890005 100
1234567890003 95
1234567890002 77
1234567890004 85
4
1234567890013 65
1234567890011 25
1234567890014 100
1234567890012 85
Sample Output:
9
1234567890005 1 1 1
1234567890014 1 2 1
1234567890001 3 1 2
1234567890003 3 1 2
1234567890004 5 1 4
1234567890012 5 2 2
1234567890002 7 1 5
1234567890013 8 2 3
1234567890011 9 2 4
思路
滑动窗口经典用法。先每个组排序,设定好排名,再混在一起,再次设定排名即可。
加一个哨兵,可以方便处理。
注意当成绩相同时,按ID大小排序。
用long long int
记得按13位格式补零,害怕自己补不好就用string
。
code
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
struct pat_stu{
long long int ID;
int loca, grade, rank, gobal_rank;
};
bool cmp(pat_stu a, pat_stu b){
if(a.grade == b.grade) return a.ID < b.ID;
return a.grade > b.grade;
}
int main(){
int n = 0, num = 0;
vector<pat_stu> list, temp;
pat_stu shao;
shao.grade = -10;
scanf("%d", &n);
for(int i = 0; i < n; i++){
scanf("%d", &num);
temp.resize(num);
for(int j = 0; j < num; j++){
temp[j].loca = i + 1;
scanf("%lld %d", &temp[j].ID, &temp[j].grade);
}
sort(temp.begin(), temp.end(), cmp);
temp.push_back(shao);
int p = 0, q = 0;
while(p < temp.size()){
if(temp[q].grade != temp[p].grade) q = p;
temp[p].rank = q + 1;
list.push_back(temp[p]);
p++;
}
list.pop_back();
temp.clear();
}
sort(list.begin(), list.end(), cmp);
printf("%d\n", list.size());
list.push_back(shao);
int p = 0, q = 0;
while(p < list.size()){
if(list[q].grade != list[p].grade) q = p;
list[p].gobal_rank = q + 1;
p++;
}
list.pop_back();
for(pat_stu s:list) printf("%013lld %d %d %d\n", s.ID, s.gobal_rank, s.loca, s.rank);
return 0;
}
PAT甲级:1025 PAT Ranking (25分)的更多相关文章
- PAT 甲级 1025 PAT Ranking
1025. PAT Ranking (25) 时间限制 200 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Programmi ...
- PAT甲级——1025 PAT Ranking
1025 PAT Ranking Programming Ability Test (PAT) is organized by the College of Computer Science and ...
- 【PAT甲级】1070 Mooncake (25 分)(贪心水中水)
题意: 输入两个正整数N和M(存疑M是否为整数,N<=1000,M<=500)表示月饼的种数和市场对于月饼的最大需求,接着输入N个正整数表示某种月饼的库存,再输入N个正数表示某种月饼库存全 ...
- PAT 甲级 1020 Tree Traversals (25分)(后序中序链表建树,求层序)***重点复习
1020 Tree Traversals (25分) Suppose that all the keys in a binary tree are distinct positive intege ...
- PAT 甲级 1146 Topological Order (25 分)(拓扑较简单,保存入度数和出度的节点即可)
1146 Topological Order (25 分) This is a problem given in the Graduate Entrance Exam in 2018: Which ...
- PAT 甲级 1071 Speech Patterns (25 分)(map)
1071 Speech Patterns (25 分) People often have a preference among synonyms of the same word. For ex ...
- PAT 甲级 1063 Set Similarity (25 分) (新学,set的使用,printf 输出%,要%%)
1063 Set Similarity (25 分) Given two sets of integers, the similarity of the sets is defined to be ...
- PAT 甲级 1059 Prime Factors (25 分) ((新学)快速质因数分解,注意1=1)
1059 Prime Factors (25 分) Given any positive integer N, you are supposed to find all of its prime ...
- PAT 甲级 1051 Pop Sequence (25 分)(模拟栈,较简单)
1051 Pop Sequence (25 分) Given a stack which can keep M numbers at most. Push N numbers in the ord ...
- PAT 甲级 1048 Find Coins (25 分)(较简单,开个数组记录一下即可)
1048 Find Coins (25 分) Eva loves to collect coins from all over the universe, including some other ...
随机推荐
- Yolov4性能分析(上)
Yolov4性能分析(上) 一.目录 实验测试 1) 测试介绍 2) Test 3) Train 二. 分析 1.实验测试 1. 1 实验测试方法 Yolov4训练train实验方法(Darkn ...
- Python_selenium PO模式下 Tesecase 的相同执行代码做成selenium_base_case公共模块及调用
作用: PO模式下 Tesecase 的相同执行代码做成selenium_base_case公共模块及调用,提高代码简洁度,实现同样效果. 框架结构: 代码简单实践: common模块下 seleni ...
- 一文带你了解.Net自旋锁
本文主要讲解.Net基于Thread实现自旋锁的三种方式 基于Thread.SpinWait实现自旋锁 实现原理:基于Test--And--Set原子操作实现 使用一个数据表示当前锁是否已经被获取 0 ...
- go语言的排序和搜索(转载)
http://studygolang.com/articles/1598 go语言的排序和搜索 晚上准备动手写点 go 的程序的时候,想起 go 如何排序的问题.排序 sort 是个基本的操作,当然搜 ...
- css--flex弹性布局详解和使用
前言 前端开发最基础的能力是根据 ui 设计稿迅速还原页面,拿到设计稿不要急于写代码,首先要对页面进行分析,对页面的整体布局有个大概的了解,然后先实现一个整体的布局,再把布局拆分成逐个小模块,逐个去实 ...
- 技术如何转产品01——1+1>2?
当业务复杂到一定阶段的时候,效率问题会首当其冲,基本解法是化整为零.分赛道,对应的产物可以是子公司>>事业部>业务单元>项目组. 好处是目标聚焦.所以问题也会聚焦,工作内容闭 ...
- Unity 消消乐开发思路
以简单的方式讲述游戏开发思路,暂时没有实践,如有错误,欢迎各位大佬指错 关卡数据保存方式 数据保存我选用json,可读性强,解析快 消消乐物体处理方式 消消乐物体我将以预制体的方式使用(把物品拖到As ...
- 诸多改进!Superset 1.2.0 正式发布!
Apache Superset 是一个现代的.企业级的轻量BI平台,提供了大量数据可视化组件. 距离superset上一个版本发布已经过了近三个月的时间,我们终于等到了1.2.0版本. 之前就曾提到过 ...
- 24、mysql数据库优化
24.1.如何判断网站慢的排查顺序: 客户端->web->nfs->数据库: 24.2.uptime命令详解: [root@backup ~]#uptime 13:03:23 up ...
- POJ 1681 高斯消元 枚举自由变元
题目和poj1222差不多,但是解法有一定区别,1222只要求出任意一解,而本题需要求出最少翻转次数.所以需要枚举自由变元,变元数量为n,则枚举的次数为1<<n次 #include < ...