题目信息

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. CREATE TABLE AS - 从一条查询的结果中创建一个新表

    SYNOPSIS CREATE [ [ GLOBAL | LOCAL ] { TEMPORARY | TEMP } ] TABLE table_name [ (column_name [, ...] ...

  2. js 上传图片、压缩、旋转

    亲测 <!doctype html> <html> <head> <meta charset="utf-8"> <title& ...

  3. Myeclipse中dubug调试出现参数显示的框

    1.步骤: window>show view>variables 结果:

  4. cssrefresh.js-CSS文件自动刷新

    一.如何使用cssrefresh.js 使用很简单,类似下面的代码: <head> <link rel="stylesheet" type="text/ ...

  5. BZOJ 2502 Luogu P4843 清理雪道 最小流

    题意: 滑雪场坐落在FJ省西北部的若干座山上. 从空中鸟瞰,滑雪场可以看作一个有向无环图,每条弧代表一个斜坡(即雪道),弧的方向代表斜坡下降的方向. 你的团队负责每周定时清理雪道.你们拥有一架直升飞机 ...

  6. NOIp模拟赛 西行妖下

    题目描述: 给出一棵n个节点的树,每个点初始m值为1. 你有三种操作: 1.Add l r k ,将l到r路径上所有点m值加k. 2.Multi l r k ,将l到r路径上所有点m值乘k. 3.Qu ...

  7. SpringAOP的简单实现

    AOP,即面向切面编程,springAOP采用的是动态代理的技术 其主要作用可以做一些与业务逻辑无关,但却必须的操作,例如日志记录,权限管理,检查数据,等等.首先,来做一个小实现来方便理解 首先,建立 ...

  8. buf.toString()

    buf.toString([encoding[, start[, end]]]) encoding {String} 默认:'utf8' start {Number} 默认:0 end {Number ...

  9. Python之目录结构

    Python之目录结构 项目名project_name project_name -|--bin (可执行文件) --|--start.py import os,sys #设置环境变量 BASE_DI ...

  10. time | sys | os 模块,递归删除文件,项目分析

    一,复习 ''' 1.跨文件夹导包 - 不用考虑包的情况下直接导入文件夹(包)下的具体模块 2.__name__: py自执行 '__main__' | py被导入执行 '模块名' 3.包:一系列模块 ...