PAT甲级 1025
来源:互联网 发布:瓣膜成形术 知乎 编辑:程序博客网 时间:2024/06/15 02:13
PAT Ranking
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
考点
- 模拟和逻辑
题解
- 按题目要求来就可以。
#include <iostream>#include <algorithm>#include <string.h>#include <stdio.h>using namespace std;#define MAXSIZE 30000+10#define INF 0x7ffffffftypedef long long ll;struct node{ ll rid; int lnum; int lr; int mark;}rst[MAXSIZE];bool cmp(node a,node b){ if(a.mark==b.mark){ return a.rid<b.rid; } return a.mark>b.mark;}int main(){ // freopen("./in","r",stdin); int location; scanf("%d",&location); int i,j; int n,mark; int rank,bufrank; int total=0; for(i=1;i<=location;i++){ scanf("%d",&n); for(j=total;j<total+n;j++){ scanf("%lld %d",&rst[j].rid,&rst[j].mark); rst[j].lnum=i; } sort(rst+total,rst+total+n,cmp); rank=1; rst[total].lr=1; bufrank=1; for(j=total+1;j<total+n;j++){ if(rst[j].mark==rst[j-1].mark){ bufrank++; }else{ rank+=bufrank; bufrank=1; } rst[j].lr=rank; } total+=n; } sort(rst,rst+total,cmp); rank=1; bufrank=1; printf("%d\n",total); printf("%013lld %d %d %d\n",rst[0].rid,rank,rst[0].lnum,rst[0].lr); for(i=1;i<total;i++){ if(rst[i].mark==rst[i-1].mark){ bufrank++; }else{ rank+=bufrank; bufrank=1; } printf("%013lld %d %d %d\n",rst[i].rid,rank,rst[i].lnum,rst[i].lr); }return 0;}
- PAT 甲级 1025 PAT Ranking
- PAT(甲级)1025
- 浙大pat甲级 1025
- PAT甲级1025
- PAT甲级 1025
- PAT 甲级
- PAT甲级 A1025.PAT RANKING
- PAT(甲级)1003
- PAT(甲级)1004
- PAT(甲级)1005
- PAT(甲级)1006
- PAT(甲级)1007
- PAT(甲级)1008
- PAT(甲级)1009
- PAT(甲级)1010
- PAT(甲级)1011
- PAT(甲级)1012
- PAT(甲级)1013
- 541. Reverse String II(C语言版本)
- const指针与函数模板的小问题
- 如何把rtl8188EUS驱动编译生成ko模块并且下载到rk平台Android4.2.2上使用
- PHP OpenSSL&Mcrypt实现AES加密
- android面试准备
- PAT甲级 1025
- laravel项目SVN部署到服务器404错误
- java对象序列化
- tensorflow74 使用tensorflow dlib opencv做特定人脸识别
- Java对象初始化详解
- php 封装微信自动登录注册方法基于thinkphp方法【php】
- 原生AJAX异步通讯使用详解
- PHP实现数组中两个数的和等于给定的目标值
- ContentProvider的总结