博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
1062 Talent and Virtue (25 分)
阅读量:4124 次
发布时间:2019-05-25

本文共 4327 字,大约阅读时间需要 14 分钟。

 

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 Hbut 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 8010000001 64 9010000002 90 6010000011 85 8010000003 85 8010000004 80 8510000005 82 7710000006 83 7610000007 90 7810000008 75 7910000009 59 9010000010 88 4510000012 80 10010000013 90 9910000014 66 60

Sample Output:

1210000013 90 9910000012 80 10010000003 85 8010000011 85 8010000004 80 8510000007 90 7810000006 83 7610000005 82 7710000002 90 6010000014 66 6010000008 75 7910000001 64 90

C++:

/* @Date    : 2018-02-02 15:19:10 @Author  : 酸饺子 (changzheng300@foxmail.com) @Link    : https://github.com/SourDumplings @Version : $Id$*//*https://www.patest.cn/contests/pat-a-practise/1062 */#include 
#include
#include
using namespace std;struct Person{ Person(int &Id, int virtue, int talent): id(Id), v(virtue), t(talent) {} int id; int v, t;};bool cmp(const Person &p1, const Person &p2){ bool result; if (p1.v + p1.t == p2.v + p2.t) { if (p1.v == p2.v) result = p1.id < p2.id; else result = p1.v > p2.v; } else result = p1.v + p1.t > p2.v + p2.t; return result;}void Output(vector
&vp){ sort(vp.begin(), vp.end(), cmp); for_each(vp.begin(), vp.end(), [] (const Person &p) { printf("%d %d %d\n", p.id, p.v, p.t);}); return;}int main(int argc, char const *argv[]){ vector
sages, noblemen, foolmen, smallmen; int N, L, H; scanf("%d %d %d", &N, &L, &H); int id; int v, t; while (N--) { scanf("%d %d %d", &id, &v, &t); if (v >= L && t >= L) { Person p(id, v, t); if (v >= H) { if (t >= H) sages.push_back(p); else noblemen.push_back(p); } else { if (v >= t) foolmen.push_back(p); else smallmen.push_back(p); } } } printf("%d\n", sages.size() + noblemen.size() + foolmen.size() + smallmen.size()); Output(sages); Output(noblemen); Output(foolmen); Output(smallmen); return 0;}

 

转载地址:http://ofrpi.baihongyu.com/

你可能感兴趣的文章
7 个适用于所有前端开发人员的很棒API,你需要了解一下
查看>>
25个构建Web项目的HTML建议,你需要了解一下!
查看>>
【web素材】02-10款大气的购物商城网站模板
查看>>
6种方式实现JavaScript数组扁平化(flat)方法的总结
查看>>
如何实现a===1 && a===2 && a===3返回true?
查看>>
49个在工作中常用且容易遗忘的CSS样式清单整理
查看>>
20种在学习编程的同时也可以在线赚钱的方法
查看>>
隐藏搜索框:CSS 动画正反向序列
查看>>
12 个JavaScript 特性技巧你可能从未使用过
查看>>
127个超级实用的JavaScript 代码片段,你千万要收藏好(上)
查看>>
【视频教程】Javascript ES6 教程27—ES6 构建一个Promise
查看>>
【5分钟代码练习】01—导航栏鼠标悬停效果的实现
查看>>
127个超级实用的JavaScript 代码片段,你千万要收藏好(中)
查看>>
8种ES6中扩展运算符的用法
查看>>
【视频教程】Javascript ES6 教程28—ES6 Promise 实例应用
查看>>
127个超级实用的JavaScript 代码片段,你千万要收藏好(下)
查看>>
【web素材】03-24款后台管理系统网站模板
查看>>
Flex 布局教程:语法篇
查看>>
年薪50万+的90后程序员都经历了什么?
查看>>
2019年哪些外快收入可达到2万以上?
查看>>