1062. Talent and Virtue (25)【排序】——PAT (Advanced Level) Practise
题目信息
1062. Talent and Virtue (25)
时间限制200 ms
内存限制65536 kB
代码长度限制16000 B
About 900 years ago, a Chinese philosopher Sima Guang wrote a history book in which he talked about people’s talent and virtue. According to his theory, a man being outstanding in both talent and virtue must be a “sage(圣人)”; being less excellent but with one’s virtue outweighs talent can be called a “nobleman(君子)”; being good in neither is a “fool man(愚人)”; yet a fool man is better than a “small man(小人)” who prefers talent than virtue.
Now given the grades of talent and virtue of a group of people, you are supposed to rank them according to Sima Guang’s theory.
Input Specification:
Each input file contains one test case. Each case first gives 3 positive integers in a line: N (<=10^5), the total number of people to be ranked; L (>=60), the lower bound of the qualified grades – that is, only the ones whose grades of talent and virtue are both not below this line will be ranked; and H (<100), the higher line of qualification – that is, those with both grades not below this line are considered as the “sages”, and will be ranked in non-increasing order according to their total grades. Those with talent grades below H but virtue grades not are cosidered as the “noblemen”, and are also ranked in non-increasing order according to their total grades, but they are listed after the “sages”. Those with both grades below H, but with virtue not lower than talent are considered as the “fool men”. They are ranked in the same way but after the “noblemen”. The rest of people whose grades both pass the L line are ranked after the “fool men”.
Then N lines follow, each gives the information of a person in the format:
ID_Number Virtue_Grade Talent_Grade
where ID_Number is an 8-digit number, and both grades are integers in [0, 100]. All the numbers are separated by a space.
Output Specification:
The first line of output must give M (<=N), the total number of people that are actually ranked. Then M lines follow, each gives the information of a person in the same format as the input, according to the ranking rules. If there is a tie of the total grade, they must be ranked with respect to their virtue grades in non-increasing order. If there is still a tie, then output in increasing order of their ID’s.
Sample Input:
14 60 80
10000001 64 90
10000002 90 60
10000011 85 80
10000003 85 80
10000004 80 85
10000005 82 77
10000006 83 76
10000007 90 78
10000008 75 79
10000009 59 90
10000010 88 45
10000012 80 100
10000013 90 99
10000014 66 60
Sample Output:
12
10000013 90 99
10000012 80 100
10000003 85 80
10000011 85 80
10000004 80 85
10000007 90 78
10000006 83 76
10000005 82 77
10000002 90 60
10000014 66 60
10000008 75 79
10000001 64 90
解题思路
按等级排序
AC代码
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;
struct Node{
int id, v1, v2, lv;
}node[100005];
bool cmp(const Node& a, const Node& b) {
if (a.lv != b.lv) return a.lv < b.lv;
if (a.v1 + a.v2 == b.v1 + b.v2){
if (a.v1 == b.v1){
return a.id < b.id;
}
return a.v1 > b.v1;
}
return a.v1 + a.v2 > b.v1 + b.v2;
}
int main()
{
int n, low, high, id, v1, v2, cnt = 0;
scanf("%d%d%d", &n, &low, &high);
for (int i = 0; i < n; ++i, ++cnt){
scanf("%d%d%d", &node[cnt].id, &node[cnt].v1, &node[cnt].v2);
if (node[cnt].v1 >= low && node[cnt].v2 >= low){
if (node[cnt].v1 >= high && node[cnt].v2 >= high){
node[cnt].lv = 1;
}else if (node[cnt].v1 >= high){
node[cnt].lv = 2;
}else if (node[cnt].v1 >= node[cnt].v2){
node[cnt].lv = 3;
}else{
node[cnt].lv = 4;
}
}else{
--cnt;
}
}
sort(node, node + cnt, cmp);
printf("%d\n", cnt);
for (int i = 0; i < cnt; ++i){
printf("%d %d %d\n", node[i].id, node[i].v1, node[i].v2);
}
return 0;
}
个人游戏推广: apkName=com.xianyun.yf" target="_blank" align="left">《10云方》与方块来次消除大战!
1062. Talent and Virtue (25)【排序】——PAT (Advanced Level) Practise的更多相关文章
- PAT甲题题解-1062. Talent and Virtue (25)-排序水题
水题,分组排序即可. #include <iostream> #include <cstdio> #include <algorithm> #include < ...
- PAT 甲级 1062 Talent and Virtue (25 分)(简单,结构体排序)
1062 Talent and Virtue (25 分) About 900 years ago, a Chinese philosopher Sima Guang wrote a histor ...
- 1062 Talent and Virtue (25分)(水)
About 900 years ago, a Chinese philosopher Sima Guang wrote a history book in which he talked about ...
- 1062 Talent and Virtue (25)
/* L (>=60), the lower bound of the qualified grades -- that is, only the ones whose grades of ta ...
- PAT (Advanced Level) 1062. Talent and Virtue (25)
简单排序.题意较长. #include<cstdio> #include<cstring> #include<cmath> #include<queue> ...
- pat 1062. Talent and Virtue (25)
难得的一次ac 题目意思直接,方法就是对virtue talent得分进行判断其归属类型,用0 1 2 3 4 表示 不合格 sage noblemen foolmen foolmen 再对序列进行排 ...
- 【PAT甲级】1062 Talent and Virtue (25 分)
题意: 输入三个正整数N,L,H(N<=1E5,L>=60,H<100,H>L),分别代表人数,及格线和高水平线.接着输入N行数据,每行包括一个人的ID,道德数值和才能数值.一 ...
- 1067. Sort with Swap(0,*) (25)【贪心】——PAT (Advanced Level) Practise
题目信息 1067. Sort with Swap(0,*) (25) 时间限制150 ms 内存限制65536 kB 代码长度限制16000 B Given any permutation of t ...
- 1078. Hashing (25)【Hash + 探測】——PAT (Advanced Level) Practise
题目信息 1078. Hashing (25) 时间限制100 ms 内存限制65536 kB 代码长度限制16000 B The task of this problem is simple: in ...
随机推荐
- CREATE TABLE - 定义一个新表
SYNOPSIS CREATE [ [ GLOBAL | LOCAL ] { TEMPORARY | TEMP } ] TABLE table_name ( { column_name data_ty ...
- call, apply, bind 区别
#call, apply, bind 区别及模拟实现call apply bind 三者都可以用来改变this的指向,但是在用法上略有不同 首先说一下call和apply的区别 call和apply ...
- 利用jquery制作滚动到指定位置触发动画
<!DOCTYPE html><html><head> <meta charset="utf-8"> <title>利用 ...
- Android图像处理之Bitmap类(1)
Bitmap是Android系统中的图像处理的最重要类之一.用它可以获取图像文件信息,进行图像剪切.旋转.缩放等操作,并可以指定格式保存图像文件.本文从应用的角度,着重介绍怎么用Bitmap来实现这些 ...
- Chrome插件:浏览器后台与页面间通信
content.js 与 background.js和popup.js 通信和 background.js与popup.js 这些通信都用 chrome.runtime.sendMessage 这个 ...
- Linux网络配置出现的问题
网络连接 : 选择桥接模式进入字符界面后,管理员登入后 ifconfig显示eth0和ol,但是不显示静态IP地址,即无inet.地址.广播.掩码 解决方案: 1.使用sudo dhclient e ...
- 十款开发者常用的Chrome插件,让chrome成为开发利器!
Chrome浏览器无论是作为浏览器市场的NO1还是其强大的跨平台能力以及丰富的扩展插件,一直是许多开发者的首要选择的浏览器.chrome浏览器也因为其丰富的Chrome插件,帮助开发者们在开发流程中极 ...
- LeetCode(53) Maximum Subarray
题目 Find the contiguous subarray within an array (containing at least one number) which has the large ...
- Python接口测试之报告(十五)
在本文章中,主要使用jenkins和编写的自动化测试代码,来生成漂亮的测试报告,关于什么是CI这些 我就不详细的介绍了,这里我们主要是实战为主. 首先搭建java的环境,这个这里不做介绍.搭建好jav ...
- 60. Spring Boot写后感【从零开始学Spring Boot】
从2016年4月15日到2016年7月20日经历长达3个月的时间,[从零开始学习Spring Boot]系列就要告一段落了.国内的各种资源都比较乱或者是copy 来copy去的,错了也不加以修正下,导 ...