码迷,mamicode.com
首页 > 其他好文 > 详细

PAT1062. Talent and Virtue

时间:2015-02-21 19:54:04      阅读:263      评论:0      收藏:0      [点我收藏+]

标签:

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 (<=105), 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

思路:此题超级水,理清思路即可
技术分享
 1 #include <iostream>
 2 #include <cstdio>
 3 #include <algorithm>
 4 #include <vector>
 5 using namespace std;
 6 #define MAX 100010
 7 struct Stu
 8 {
 9     int Id;
10     int vir;
11     int tal;
12     int total;
13 };
14 bool cmp(Stu A,Stu B)
15 {
16     if(A.total!=B.total)
17     {
18         return A.total>B.total;
19     }
20     else if(A.vir!=B.vir)
21     {
22         return A.vir>B.vir;
23     }
24     else
25        return A.Id<B.Id;
26 }
27 int main(int argc, char *argv[])
28 {
29     int N,L,H;
30     vector<Stu>sage,noble,fool,res;
31     scanf("%d%d%d",&N,&L,&H);
32     for(int i=0;i<N;i++)
33     {
34         int id,virtue,talent;
35         scanf("%d%d%d",&id,&virtue,&talent);
36         if(virtue<L||talent<L)
37           continue;
38         Stu tem;
39         tem.Id=id;
40         tem.vir=virtue;
41         tem.tal=talent;
42         tem.total=virtue+talent;
43         if(virtue>=H&&talent>=H)
44           sage.push_back(tem);
45         else if(virtue>=H&&talent<H)
46           noble.push_back(tem);
47         else if(virtue<H&&talent<H&&virtue>=talent)
48           fool.push_back(tem);
49         else
50            res.push_back(tem);
51         
52     }
53     sort(sage.begin(),sage.begin()+sage.size(),cmp);
54     sort(noble.begin(),noble.begin()+noble.size(),cmp);
55     sort(fool.begin(),fool.begin()+fool.size(),cmp);
56     sort(res.begin(),res.begin()+res.size(),cmp); 
57     printf("%d\n",sage.size()+noble.size()+fool.size()+res.size());
58     for(int i=0;i<sage.size();i++)
59     {
60         printf("%08d %d %d\n",sage[i].Id,sage[i].vir,sage[i].tal);
61     } 
62     for(int i=0;i<noble.size();i++)
63     {
64         printf("%08d %d %d\n",noble[i].Id,noble[i].vir,noble[i].tal);
65     } 
66     for(int i=0;i<fool.size();i++)
67     {
68         printf("%08d %d %d\n",fool[i].Id,fool[i].vir,fool[i].tal);
69     } 
70     for(int i=0;i<res.size();i++)
71     {
72         printf("%08d %d %d\n",res[i].Id,res[i].vir,res[i].tal);
73     } 
74     return 0;
75 }
View Code

 

PAT1062. Talent and Virtue

标签:

原文地址:http://www.cnblogs.com/GoFly/p/4297121.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!