PAT_A1062#Talent and Virtue
Source:
Description:
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 (≤), the total number of people to be ranked; L (≥), 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 (<), 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 Lline 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 (≤), 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
Keys:
- 模拟题
Code:
/*
Data: 2019-07-15 18:19:51
Problem: PAT_A1062#Talent and Virtue
AC: 18:55 题目大意:
圣人:德才 >= H
君子:德 >= H
愚人:德 >= 才
小人:余下者
输入:
第一行给出,人数N<=1e5,及格线L>=60,优秀线H<100
接下来N行,id,virture, talent
输出:
第一行给出,有效人数M
接下来M行,按照圣人,君子,愚人,小人的顺序,按成绩递减输出(德才,德,id)
*/ #include<cstdio>
#include<vector>
#include<algorithm>
using namespace std;
struct node
{
int id,mark;
int vir,tal;
}temp;
vector<node> ans; bool cmp(const node &a, const node &b)
{
if(a.mark != b.mark)
return a.mark < b.mark;
else if(a.vir+a.tal != b.vir+b.tal)
return a.vir+a.tal > b.vir+b.tal;
else if(a.vir != b.vir)
return a.vir > b.vir;
else
return a.id < b.id;
} int main()
{
#ifdef ONLINE_JUDGE
#else
freopen("Test.txt", "r", stdin);
#endif int n,l,h;
scanf("%d%d%d", &n,&l,&h);
for(int i=; i<n; i++)
{
scanf("%d%d%d", &temp.id,&temp.vir,&temp.tal);
if(temp.vir>=l && temp.tal>=l)
{
if(temp.vir>=h && temp.tal>=h)
temp.mark=;
else if(temp.vir>=h)
temp.mark=;
else if(temp.vir>=temp.tal)
temp.mark=;
else
temp.mark=;
ans.push_back(temp);
}
}
sort(ans.begin(),ans.end(),cmp);
printf("%d\n", ans.size());
for(int i=; i<ans.size(); i++)
printf("%08d %d %d\n", ans[i].id,ans[i].vir,ans[i].tal); return ;
}
PAT_A1062#Talent and Virtue的更多相关文章
- 1062 Talent and Virtue (25)
/* L (>=60), the lower bound of the qualified grades -- that is, only the ones whose grades of ta ...
- PAT-B 1015. 德才论(同PAT 1062. Talent and Virtue)
1. 在排序的过程中,注意边界的处理(小于.小于等于) 2. 对于B-level,这题是比較麻烦一些了. 源代码: #include <cstdio> #include <vecto ...
- 1062.Talent and Virtue
About 900 years ago, a Chinese philosopher Sima Guang wrote a history book in which he talked about ...
- 1062 Talent and Virtue (25 分)
1062 Talent and Virtue (25 分) About 900 years ago, a Chinese philosopher Sima Guang wrote a history ...
- PAT 1062 Talent and Virtue[难]
1062 Talent and Virtue (25 分) About 900 years ago, a Chinese philosopher Sima Guang wrote a history ...
- PAT 1062 Talent and Virtue
#include <cstdio> #include <cstdlib> #include <cstring> #include <vector> #i ...
- pat1062. Talent and Virtue (25)
1062. Talent and Virtue (25) 时间限制 200 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Li Abou ...
- 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 ...
- PAT 甲级 1062 Talent and Virtue (25 分)(简单,结构体排序)
1062 Talent and Virtue (25 分) About 900 years ago, a Chinese philosopher Sima Guang wrote a histor ...
随机推荐
- Hive 数据类型转换(转)
原文连接:https://www.iteblog.com/archives/892.html 在<Hive内置数据类型>文章中,我们提到了Hive内置数据类型由基本数据类型和复杂数据类型组 ...
- HTML-参考手册: HTML 语言代码
ylbtech-HTML-参考手册: HTML 语言代码 1.返回顶部 1. HTML 语言代码 参考手册 ISO 语言代码 HTML 的 lang 属性可用于声明网页或部分网页的语言.这对搜索引擎和 ...
- 【计算机网络mooc】一、概述
1.网络概述: 网络分成两个层级,用交换机连接的是子网,用路由器连接的是互连网. 互联网Internet是一个特定的互连网internet 发展3阶段,第3阶段:ISP,互联网服务提供商,缴纳费用获得 ...
- laravel新增路由文件
除去原有路由文件,有时为方便路由管理,我们可以新增独立路由文件,如:针对管理后台的路由文件. 1.在routes文件夹下创建新路由文件admin.php 2.在app\Providers\RouteS ...
- Java对象finalize()方法
Java提供了一种在对象即将被销毁时执行资源释放的方法.在Java中创建对象,但是不能销毁对象.JVM运行一个称为垃圾收集器的低优先级特殊任务来销毁不再引用的所有对象. 垃圾回收器给我们一个机会,在对 ...
- 数据库全表扫描的SQL种类
1.所查询的表的条件列没有索引: 2.需要返回所有的行: 3.对索引主列有条件限制,但是使用了函数,则Oracle 使用全表扫描,如: where upper(city)=’TOKYO’; 这样的语 ...
- C语言注意事项
#include <stdio.h> int main() { /*********************************************** * 指针使用注意事项: * ...
- tail - 输出文件的末尾部分
SYNOPSIS(总览) ../src/tail [OPTION]... [FILE]... DESCRIPTION(描述) 在标准输出上显示每个FILE的最后10行. 如果多于一个FILE,会一个接 ...
- NFS服务的安装
NFS服务的安装 1.环境准备 2.安装服务 [root@localhost ~]# yum -y install nfs-utils因为centos7自带了rpcbind,所以不用安装rpc服务,r ...
- HDU-5215 Cycle 无向图判奇环偶环
题意:给一个无向图,判断这个图是否存在奇环和偶环. 解法:网上有一种只用dfs就能做的解法,但是我不太理解. 这里用的是比较复杂的.首先奇环很简单可以用二分图染色判断.问题是偶环怎么判断?这里我们想, ...