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 ...
随机推荐
- GVS案例分享|乘新时代姑苏舫号,体验匠心智能控制
水,是苏州的灵魂,串起苏州的古与今.动与静.金鸡湖景区位于苏州工业园区,总面积11.5平方公里,其中水域面积7.4平方公里. 新时代姑苏舫号,是金鸡湖景区极具苏式特征且规格超高的游览船型.船体分为上下 ...
- thymeleaf+Springboot实现自定义标签
在项目开发中,有一些组件不能满足我们快速开发的要求,我们需要封装一些组件来更加的便利我们.比如,我们可以封装一个下拉框组件,只要开发人员只有引用这个组件的标签,就能出现效果,而不用再去请求url,渲染 ...
- JVM Ecosystem Report 2020 (2020年JVM生态系统报告)
本文翻译自SNYK于2020年发布的< JVM Ecosystem Report 2020 >,全文使用机器翻译自动生成,人为将翻译的离谱和翻译明显错误的地方修正到勉强能看懂的程度. 英语 ...
- P5837 [USACO19DEC]Milk Pumping G
题目描述 Farmer John 最近为了扩张他的牛奶产业帝国而收购了一个新的农场.这一新的农场通过一个管道网络与附近的小镇相连,FJ 想要找出其中最合适的一组管道,将其购买并用来将牛奶从农场输送到小 ...
- RabbitMQ由浅入深入门全总结(二)
写在最前面 距离上一次发文章已经很久了,其实这段时间一直也没有停笔,只不过在忙着找工作还有学校结课的事情,重新弄了一下博客,后面也会陆陆续续会把文章最近更新出来~ 这篇文章有点长,就分了两篇 PS:那 ...
- 【NX二次开发】根据视图名称获取视图的矩阵
函数:uc6433 () 函数说明:获取视图名称对应的矩阵值.视图名称分为几类: 1. 制图中的视图,右键属性可以查看名称 获取上图中的视图的矩阵: 1 double v_mtx[9] = { 1.0 ...
- Spring Cloud Alibaba(15)---Sleuth+Zipkin
SpringCloudAlibaba整合Sleuth+Zipkin 有关Sleuth之前有写过两篇文章 Spring Cloud Alibaba(13)---Sleuth概述 Spring Cloud ...
- 【题解】斐波拉契 luogu3938
题目 题目描述 小 C 养了一些很可爱的兔子. 有一天,小 C 突然发现兔子们都是严格按照伟大的数学家斐波那契提出的模型来进行 繁衍:一对兔子从出生后第二个月起,每个月刚开始的时候都会产下一对小兔子. ...
- Pandas高级教程之:处理text数据
目录 简介 创建text的DF String 的方法 columns的String操作 分割和替换String String的连接 使用 .str来index extract extractall c ...
- DOS命令行(11)——更多实用的命令行工具
start 启动另一个窗口运行指定的程序或命令,所有的DOS命令和命令行程序都可以由start命令来调用.该命令不仅能运行程序,还能运行协议对应的程序 命令格式:START ["title& ...