题目信息

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

  1. PAT甲题题解-1062. Talent and Virtue (25)-排序水题

    水题,分组排序即可. #include <iostream> #include <cstdio> #include <algorithm> #include < ...

  2. PAT 甲级 1062 Talent and Virtue (25 分)(简单,结构体排序)

    1062 Talent and Virtue (25 分)   About 900 years ago, a Chinese philosopher Sima Guang wrote a histor ...

  3. 1062 Talent and Virtue (25分)(水)

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

  4. 1062 Talent and Virtue (25)

    /* L (>=60), the lower bound of the qualified grades -- that is, only the ones whose grades of ta ...

  5. PAT (Advanced Level) 1062. Talent and Virtue (25)

    简单排序.题意较长. #include<cstdio> #include<cstring> #include<cmath> #include<queue> ...

  6. pat 1062. Talent and Virtue (25)

    难得的一次ac 题目意思直接,方法就是对virtue talent得分进行判断其归属类型,用0 1 2 3 4 表示 不合格 sage noblemen foolmen foolmen 再对序列进行排 ...

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

    题意: 输入三个正整数N,L,H(N<=1E5,L>=60,H<100,H>L),分别代表人数,及格线和高水平线.接着输入N行数据,每行包括一个人的ID,道德数值和才能数值.一 ...

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

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

随机推荐

  1. vs code 用户代码片段 html.json

    {     // Place your snippets for html here. Each snippet is defined under a snippet name and has a p ...

  2. MFC中调用Windows API函数的方式

    windows aoi 函数的调用前面加::

  3. vue脚手架工具vue-cli

    一.什么 是脚手架工具vue-cli? 类似于工人手里面的脚手架一样,帮助工人搭架子用,同样的vue脚手架工具也是帮助我们更好更快速的开发代码的工具 二.vue-cli能做什么? 三.vue-cli安 ...

  4. mac vim编辑器常用操作快捷方式

    0 行首$ (shift+6)行尾gg 文首G(shift+g) 文尾A(Shift+a)文尾,并编辑ctrl+f 向上翻页ctrl+b 向下翻页ctrl+u 向上翻半页ctrl+d 向下翻半页数字+ ...

  5. Bzoj4899 记忆的轮廓

    B. 记忆的轮廓 题目描述 通往贤者之塔的路上,有许多的危机.我们可以把这个地形看做是一颗树,根节点编号为1,目标节点编号为n,其中1-n的简单路径上,编号依次递增,在[1,n]中,一共有n个节点.我 ...

  6. 离线缓存 application cache

    1. 什么是离线缓存: 离线缓存可以将站点的一些文件缓存到本地,它是浏览器自己的一种机制,将需要的文件缓存下来,以便后期即使没有连接网络,被缓存的页面也可以展示. 例子:比如我们在手机或电脑上访问一个 ...

  7. 等待某(N)个线程执行完再执行某个线程的几种方法(Thread.join(),CountDownLatch,CyclicBarrier,Semaphore)

    1.main线程中先调用threadA.join() ,再调用threadB.join()实现A->B->main线程的执行顺序 调用threadA.join()时,main线程会挂起,等 ...

  8. POJ1222熄灯问题【位运算+枚举】

    EXTENDED LIGHTS OUT Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 14231   Accepted: 8 ...

  9. STM32F407 GPIO原理 个人笔记

    datasheet(STM32F407ZGT6.pdf)中,IO structure 为FT,表示容忍5V电压 后面的uart1_TX之类,表示端口复用 共有A~G7组IO口, 每组16个IO口:0~ ...

  10. 家的范围 Home on the Range(洛谷 2733)

    题目背景 农民约翰在一片边长是N (2 <= N <= 250)英里的正方形牧场上放牧他的奶牛.(因为一些原因,他的奶牛只在正方形的牧场上吃草.)遗憾的是,他的奶牛已经毁坏一些土地.( 一 ...