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分)的更多相关文章

  1. PAT 甲级 1025 PAT Ranking

    1025. PAT Ranking (25) 时间限制 200 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Programmi ...

  2. PAT甲级——1025 PAT Ranking

    1025 PAT Ranking Programming Ability Test (PAT) is organized by the College of Computer Science and ...

  3. 【PAT甲级】1070 Mooncake (25 分)(贪心水中水)

    题意: 输入两个正整数N和M(存疑M是否为整数,N<=1000,M<=500)表示月饼的种数和市场对于月饼的最大需求,接着输入N个正整数表示某种月饼的库存,再输入N个正数表示某种月饼库存全 ...

  4. PAT 甲级 1020 Tree Traversals (25分)(后序中序链表建树,求层序)***重点复习

    1020 Tree Traversals (25分)   Suppose that all the keys in a binary tree are distinct positive intege ...

  5. PAT 甲级 1146 Topological Order (25 分)(拓扑较简单,保存入度数和出度的节点即可)

    1146 Topological Order (25 分)   This is a problem given in the Graduate Entrance Exam in 2018: Which ...

  6. PAT 甲级 1071 Speech Patterns (25 分)(map)

    1071 Speech Patterns (25 分)   People often have a preference among synonyms of the same word. For ex ...

  7. 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 ...

  8. 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 ...

  9. 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 ...

  10. PAT 甲级 1048 Find Coins (25 分)(较简单,开个数组记录一下即可)

    1048 Find Coins (25 分)   Eva loves to collect coins from all over the universe, including some other ...

随机推荐

  1. swagger 注解使用

    @Api() 用于类:表示标识这个类是swagger的资源 tags–表示说明 value–也是说明,可以使用tags替代 但是tags如果有多个值,会生成多个list @ApiOperation() ...

  2. postman实现参数化执行及断言处理

    一.假设需要做的测试的参数如下: 注意保存为.csv文件时一定要选择格式为UTF-8 ,避免乱码. 二.输入参数和期望结果在postman中的用法: 注意一定要通过runner的方式进行运行,选择对应 ...

  3. sql优化_隐式-显示转换

    ========  测试表1信息   =======SQL> select count(*) from tb_test; COUNT(*)----------   3000000   SQL&g ...

  4. Java8 Lambda表达式、Optional类浅析

    1.概念 Lambda是一个匿名函数,可以将其理解为一段可以传递的代码(将代码像数据一样进行传递)可以写出更简洁.更灵活的代码.作为一种更紧凑的代码风格,使得java语言的表达能利得到了提升. 2. ...

  5. 【NX二次开发】Block UI NXOpen::BlockStyler::BlockDialog

    定义: NXOpen::BlockStyler::BlockDialog* theDialog; theDialog->PerformApply();//执行应用并重新启动对话框. theDia ...

  6. 聚类算法K-Means算法和Mean Shift算法介绍及实现

    Question:什么是聚类算法 1.聚类算法是一种非监督学习算法 2.聚类是在没有给定划分类别的情况下,根据数据相似度进行样本分组的一种方法 3.理论上,相同的组的数据之间有相同的属性或者是特征,不 ...

  7. Message、Handler、Message Queue、Looper 之间的关系

    单线程模型中Message.Handler.Message Queue.Looper之间的关系 1.Message Message即为消息,可以理解为线程间交流的信息.处理数据后台线程需要更新UI,你 ...

  8. kustomize简单使用

    1.背景 在Kubernetes v1.14版本的发布说明中,kustomize 成为了 kubectl 内置的子命令,并说明了 kustomize 使用 Kubernetes 原生概念帮助用户创作并 ...

  9. (C++)戳西瓜

    写在前面的话: 请不要吝啬你的点赞!!! 题目描述 有 n 个西瓜,编号为0 到 n-1,每个西瓜上都标有一个数字,这些数字存在数组 nums 中. 现在要求你戳破所有的西瓜.每当你戳破一个西瓜 i ...

  10. CRM系统为什么达不到预期效果?

    随着信息技术的发展,企业对于信息化转型的需求越发强烈,而CRM客户关系管理系统成为了企业信息化转型的首选.尽管CRM系统对于企业有着很重要的作用,但有不少企业在选型和实施时遇到了问题,导致CRM系统没 ...