1062 Talent and Virtue (25分)(水)
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 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 (≤), 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
题目分析:想直接在一个vector处理 但是导致compare函数写的不对 在读入数据时 就将属于不同类别的先归类 再进行排序
#define _CRT_SECURE_NO_WARNINGS
#include <climits>
#include<iostream>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<algorithm>
#include<string>
#include<cmath>
using namespace std;
struct Person {
int Id;
int Vir_Grade;
int Tal_Grade;
};
int N, L, H;
vector<Person> P[];
bool compare(const Person& a, const Person& b)
{
int Grade_a = a.Tal_Grade + a.Vir_Grade;
int Grade_b = b.Tal_Grade + b.Vir_Grade;
if (Grade_a != Grade_b)
return Grade_a > Grade_b;
else if (a.Vir_Grade != b.Vir_Grade)
return a.Vir_Grade > b.Vir_Grade;
else return a.Id < b.Id;
}
int main()
{ scanf("%d %d %d", &N,&L,&H);
for(int i=;i<N;i++)
{
int id;
int V_Grade, T_Grade;
scanf("%d %d %d", &id, &V_Grade, &T_Grade);
if (V_Grade < L || T_Grade < L)continue;
if (V_Grade >= H && T_Grade >= H)
P[].push_back({ id,V_Grade,T_Grade });
else if (V_Grade>=H && T_Grade < H)
P[].push_back({ id,V_Grade,T_Grade });
else if(V_Grade<H&&T_Grade<H&&V_Grade>=T_Grade)
P[].push_back({ id,V_Grade,T_Grade });
else
P[].push_back({ id,V_Grade,T_Grade });
}
int size = ;
for (int i = ; i <; i++)
{
size += P[i].size();
sort(P[i].begin(), P[i].end(), compare);
}
cout << size << endl;
for (int i = ; i < ; i++)
for (auto it : P[i])
cout << it.Id << " " << it.Vir_Grade << " " << it.Tal_Grade << endl;
return ;
}
1062 Talent and Virtue (25分)(水)的更多相关文章
- PAT 甲级 1062 Talent and Virtue (25 分)(简单,结构体排序)
1062 Talent and Virtue (25 分) About 900 years ago, a Chinese philosopher Sima Guang wrote a histor ...
- PAT甲题题解-1062. Talent and Virtue (25)-排序水题
水题,分组排序即可. #include <iostream> #include <cstdio> #include <algorithm> #include < ...
- 【PAT甲级】1062 Talent and Virtue (25 分)
题意: 输入三个正整数N,L,H(N<=1E5,L>=60,H<100,H>L),分别代表人数,及格线和高水平线.接着输入N行数据,每行包括一个人的ID,道德数值和才能数值.一 ...
- 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 ...
- 1062 Talent and Virtue (25)
/* L (>=60), the lower bound of the qualified grades -- that is, only the ones whose grades of ta ...
- pat 1062. Talent and Virtue (25)
难得的一次ac 题目意思直接,方法就是对virtue talent得分进行判断其归属类型,用0 1 2 3 4 表示 不合格 sage noblemen foolmen foolmen 再对序列进行排 ...
- PAT (Advanced Level) 1062. Talent and Virtue (25)
简单排序.题意较长. #include<cstdio> #include<cstring> #include<cmath> #include<queue> ...
- 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 分)
1062 Talent and Virtue (25 分) About 900 years ago, a Chinese philosopher Sima Guang wrote a history ...
随机推荐
- 开发RTSP 直播软件 H264 AAC 编码
上一篇对摄像头预览,拍照做了大概的介绍,现在已经可以拿到视频帧了,在加上 RTSP 实现,就是直播的雏形,当然还要加上一些 WEB 管理和手机平台的支援,就是一整套直播软件. 介绍一些基础概念:RTP ...
- Mozilla的 Firefox Graphics 团队向社区寻求重现WebRender bug的方法
导读 Mozilla 的 Firefox Graphics 团队正在向社区寻求帮助,由于他们收到了一些随机发生的 UI 错误报告,却一直无法找出错误的重现步骤(STR),因此现在向外寻求社区用户的帮助 ...
- 通过CGAL将一个多边形剖分成Delaunay三角网
目录 1. 概述 2. 实现 3. 结果 4. 参考 1. 概述 对于平面上的点集,通过Delaunay三角剖分算法能够构建一个具有空圆特性和最大化最小角特性的三角网.空圆特性其实就是对于两个共边的三 ...
- vquery 一些应用
// JavaScript Document function myAddEvent(obj,sEv,fn){ if(obj.attachEvent){ obj.attachEvent('on'+sE ...
- 2019.3.14解题报告&补题报告
A题 题意: 输入r, c,代表r*c的矩阵,接下来一行,是r个数,代表每一行里最大的数:接下来一行,是c个数,代表每一列中的最大数.求所给数据是否冲突. 思路:判断r个数中最大数maxr和c个数中最 ...
- 杂谈 | 增量思维v.s.存量思维
无挂碍故,无有恐怖,远离颠倒梦想,究竟涅槃. ——<心经> 声明在前,本文并不是要论述“存量思维”是不好的, 而是整理某些场景下需要摒弃“存量思维”,或者提倡“增量思维”. 1 ...
- jvm 性能调优工具之 jstat 命令详解
Jstat名称:Java Virtual Machine statistics monitoring tool 官方文档:https://docs.oracle.com/javase/1.5.0/do ...
- ERP系统定价模型及费用组成
很多人选择ERP系统的时候最关心的就是费用问题,因为很多中小企业资金都是比较缺乏的,如果需要使用大量的金钱来购买ERP系统这是不现实的.你知道ERP系统的定价模型有哪些吗?你知道影响ERP系统价格的因 ...
- CompTIA Security+ 常见知识点
前言: Security+ 认证是一种中立第三方认证,其发证机构为美国计算机行业协会CompTIA: 是和CISSP.CISA等共同包含在内的国际IT业热门认证之一,和CISSP偏重信息安全管理相比, ...
- java 为什么重写equals一定要重写hashcode?
前言 最近复习,又看到了这个问题,在此记录和整理,通过例子来说明这种情况的原因,使大家可以清晰明白这个问题. 初步探索 首先我们要了解equals方法是什么,hashcode方法是什么. equals ...