1062 Talent and Virtue (25 分)
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 (≤105), 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
分析:水题,sort排序即可
/**
* Copyright(c)
* All rights reserved.
* Author : Mered1th
* Date : 2019-02-25-01.10.26
* Description : A1062
*/
#include<cstdio>
#include<cstring>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<string>
#include<unordered_set>
#include<map>
#include<vector>
#include<set>
using namespace std;
int n,l,h;
struct Node{
int id,vg,tg;
int total;
int flag;
}node[];
bool cmp(Node a,Node b){
if(a.flag!=b.flag) return a.flag<b.flag;
else if(a.total!=b.total) return a.total>b.total;
else if(a.vg!=b.vg) return a.vg>b.vg;
else return a.id<b.id;
}
int main(){
#ifdef ONLINE_JUDGE
#else
freopen("1.txt", "r", stdin);
#endif
cin>>n>>l>>h;
int id,vg,tg,num=n;
;i<n;i++){
scanf("%d%d%d",&id,&vg,&tg);
node[i].id=id;
node[i].vg=vg;
node[i].tg=tg;
node[i].total=vg+tg;
if(vg<l || tg<l){
node[i].flag=;
num--;
}
else if(vg>=h &&tg>=h){
node[i].flag=;
}
else if(vg>=h &&tg<h){
node[i].flag=;
}
else if(vg<h && tg<h && vg>=tg){
node[i].flag=;
}
else{
node[i].flag=;
}
}
sort(node,node+n,cmp);
printf("%d\n",num);
;i<num;i++){
cout<<node[i].id<<" "<<node[i].vg<<" "<<node[i].tg<<endl;
}
;
}
1062 Talent and Virtue (25 分)的更多相关文章
- 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 ...
- 【PAT甲级】1062 Talent and Virtue (25 分)
题意: 输入三个正整数N,L,H(N<=1E5,L>=60,H<100,H>L),分别代表人数,及格线和高水平线.接着输入N行数据,每行包括一个人的ID,道德数值和才能数值.一 ...
- 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 Chine ...
- 1062 Talent and Virtue (25)
/* L (>=60), the lower bound of the qualified grades -- that is, only the ones whose grades of ta ...
- pat 1062. Talent and Virtue (25)
难得的一次ac 题目意思直接,方法就是对virtue talent得分进行判断其归属类型,用0 1 2 3 4 表示 不合格 sage noblemen foolmen foolmen 再对序列进行排 ...
- PAT (Advanced Level) 1062. Talent and Virtue (25)
简单排序.题意较长. #include<cstdio> #include<cstring> #include<cmath> #include<queue> ...
- PAT甲题题解-1062. Talent and Virtue (25)-排序水题
水题,分组排序即可. #include <iostream> #include <cstdio> #include <algorithm> #include < ...
- pat1062. Talent and Virtue (25)
1062. Talent and Virtue (25) 时间限制 200 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Li Abou ...
随机推荐
- http指定状态码
Http状态代码 1.指定状态码: setStatus HttpServletResponse的setStatus方法.如果响应的状态代码比较特殊,并且伴有相关的文档内容,那么一定要在用PrintWr ...
- NodeJS 难点(网络,文件)的 核心 stream 一:Buffer
stream应用一图片转存服务 stream github教程 文件操作和网络都依赖了一个很重要的对象—— Stream, 而这个 <node深入浅出> 没有分析的, 所以读完这本书, 在 ...
- Python mode_r
f = open("例子.txt",mode="r",encoding="utf-8") print(f.read(5)) # 读取5个字符 ...
- mos如何工作参考地址
https://wenku.baidu.com/view/c118c3fb360cba1aa811da9d.html?qq-pf-to=pcqq.c2c
- 51Nod 1058: N的阶乘的长度(斯特林公式)
1058 N的阶乘的长度 基准时间限制:1 秒 空间限制:131072 KB 分值: 0 难度:基础题 收藏 关注 输入N求N的阶乘的10进制表示的长度.例如6! = 720,长度为3. Inp ...
- NSObject之一
Objective-C中有两个NSObject,一个是NSObject类,另一个是NSObject协议.而其中NSObject类采用了NSObject协议.在本文中,我们主要整理一下NSObject类 ...
- CTF密码学之凯撒加密
在加密的各种算法中,凯撒加密是最简单的也是最常见的一种加密方法,它的中心思想是替换,ROT加密其实就是凯斯加密的变种. 即明文的所有字母都在字母表上向后(或向前)按照一个固定数目进行偏移后被替换成密文 ...
- POJ3669解题报告(bfs)
POJ3669http://poj.org/problem?id=3669 很明显是一道bfs的题目 由于陨石的降临具有时刻性,所以地图是随时间变化的, 所以可以使用结构体来存储陨石下落的时刻以及位置 ...
- hdu1281 棋盘游戏 二分图最大匹配
小希和Gardon在玩一个游戏:对一个N*M的棋盘,在格子里放尽量多的一些国际象棋里面的“车”,并且使得他们不能互相攻击,这当然很简单,但是Gardon限制了只有某些格子才可以放,小希还是很轻松的解决 ...
- CH4101 银河英雄传说
题意 4101 银河英雄传说 0x40「数据结构进阶」例题 描述 公元五八○一年,地球居民迁移至金牛座α第二行星,在那里发表银河联邦创立宣言,同年改元为宇宙历元年,并开始向银河系深处拓展. 宇宙历七 ...