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

结尾无空行

英文版德才论,本题就是一个费时间的题目,如果你陷入了坑,那么得 25 将会耗费很长时间。所以在写之前,就应该分析一下,哪些是可能出现的坑,比如:题目中没有说分数一定是整数把好像,所以先用 double 存储,德才论,结构体有一个 type 来鉴别类型,文章中说低于 h,但是也得高于 l 阿,这个坑不能跳,cmp 函数内部条件不能漏,必须读懂题目。

#include<iostream>
#include<bits/stdc++.h>
#include<string>
#include<set>
#include<map>
#include<vector>
#include<queue>
#include<deque>
#include<unordered_set>
#include<unordered_map>
#include<cctype>
#include<algorithm>
#include<stack>
using namespace std;
const int N = 100001;
struct Node {int type;double vir;double tal;double sum;string id;
};
vector<Node> v;
bool cmp (Node a, Node b) {if (a.type == b.type) {if (a.sum == b.sum) {if (a.vir == b.vir) {return a.id < b.id;}return a.vir > b.vir;}return a.sum > b.sum;}return a.type < b.type;
}
int main() {int n, l, h;cin >> n >> l >> h;for (int i = 0; i < n; i++) {string id;double vir, tal;cin >> id >> vir >> tal;Node a;if (vir >= h && tal >= h) {a.id = id;a.type = 1;a.vir = vir;a.tal = tal;a.sum = vir + tal;v.push_back(a);} else if (tal < h && tal >= l && vir >= h) {a.id = id;a.type = 2;a.vir = vir;a.tal = tal;a.sum = vir + tal;v.push_back(a);} else if (tal >= l && tal < h && vir >= l &&  vir < h && vir >= tal) {a.id = id;a.type = 3;a.vir = vir;a.tal = tal;a.sum = vir + tal;v.push_back(a);} else if (tal >= l && vir >= l) {a.id = id;a.type = 4;a.vir = vir;a.tal = tal;a.sum = vir + tal;v.push_back(a);}}sort(v.begin(), v.end(), cmp);cout << v.size() << endl;for (int i = 0; i < v.size(); i++) {printf("%s %d %d\n", v[i].id.c_str(), (int)v[i].vir, (int)v[i].tal);}return 0;
}

1062 Talent and Virtue (25 分)(坑点分析)相关推荐

  1. 1062 Talent and Virtue (25 分)

    1062 Talent and Virtue (25 分) 题意 先给出三个数N(成员人数),L(及格线),H(优秀线) 给出一组成员信息,包括id,品德,才能,给这组成员排序. 当该成员品德和才能都 ...

  2. 1062 Talent and Virtue (25分)

    题目地址 About 900 years ago, a Chinese philosopher Sima Guang wrote a history book in which he talked a ...

  3. 【PAT甲级】1062 Talent and Virtue (25分)

    解题过程的小记录,如有错误欢迎指出. 小导航~ 题目分析 注意点 我的解题过程 思路 bug 代码 dalao的代码 借鉴点 题目分析 对一组人的德才分按照给定的规则进行排序 注意点 弄清楚一共分为四 ...

  4. PAT A1062 Talent and Virtue (25分)

    题意:德才均大于及格线low的才进行排序,排序的人按种姓分为 :) sages-nobleman-fool man-trash 对于人的类型的排序只需要在结构体中加入一个int type即可,通过这个 ...

  5. 1062 Talent and Virtue 25

    1062 Talent and Virtue 25 题目链接:A1062 Talent and Virtue 25 问题思路 我尝试了两种思路: 根据每个人的分数确定其是哪个级别(rank)的人,以总 ...

  6. 1062. Talent and Virtue (25)-PAT甲级真题

    About 900 years ago, a Chinese philosopher Sima Guang wrote a history book in which he talked about ...

  7. 1062. Talent and Virtue (25)

    About 900 years ago, a Chinese philosopher Sima Guang wrote a history book in which he talked about ...

  8. PAT甲级1062 Talent and Virtue:[C++题解]结构体、哈希表

    文章目录 题目分析 题目来源 题目分析 来源:acwing 分析: 分4个vector,单独排序即可. ac代码 #include<bits/stdc++.h> using namespa ...

  9. PAT 甲级 1062 Talent and Virtue

    1062 Talent and Virtue 题目大意:给出一组人数,按照要求分类再排序输出.圣人是virtue和talent都超过h的人,君子是virtue超过h并且talent位于[l,h)区间内 ...

最新文章

  1. linux-windows主动推送文件同步目录数据 linux-windows数据目录同步
  2. access开发精要(15)-货币与数字类型格式(3)
  3. 酷客多基金在济南大学成立“酷客多奖助学金“
  4. 东南大学计算机学院方效林,方效林
  5. mPaas 运维流程介绍
  6. 解析Winndows 2000/XP物理内存管理
  7. IXMLDOMDocument 成員
  8. Cannot create PoolableConnectionFactory。创建连接池异常
  9. sqlserver date类型和字符串比较_Mongo的数据类型
  10. python多线程提高速度_Python3如何使用多线程升程序运行速度
  11. 扎克伯格13年前写的Facebook网站代码,你见过吗?
  12. 每天一道剑指offer-对称的二叉树
  13. VS2008中MFC界面编程Caption中文全是乱码的解决办法 -转载
  14. DialogFragment初探路
  15. 微计算机控制器功能是什么意思,微型计算机中,控制器的基本功能是().
  16. python django 下载多个文件,接收多个文件
  17. 小米手环如何连接苹果手机
  18. FastDFS安装步骤
  19. python根据坐标画点并标记_python-如何使用colormap为matplotlib散点图中的特定点设置标记类型...
  20. 固态变 SATAFIRM S11

热门文章

  1. matlab建立mex,手把手教你在VC++中建立MEX文件及调试
  2. 三大攻略破TD手机节能之困
  3. html 表单提交 地址栏 显示=%cc%ed%bc%d3 ,html--表单(示例代码)
  4. 分享5款同类软件中的翘楚,属于是WIN10必备良品
  5. VLC的ACtiveX插件使用方法
  6. 高通Android手机软件开发培训
  7. UVA10791 Minimum Sum LCM(数论)
  8. Spring+SpringMVC+MyBatis框架搭建-----详细教程
  9. ubuntu 系统监控工具
  10. 《The Art of Assembly Language》中文名:汇编语言编程艺术 中英文正式版本下载