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 (<=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
 
题目大意:给出一些人的virtue和talent分数,以及及格分和优秀分, 两者均高于及格的才能被排名, 两者均高于优秀分的被称作sage,virute不低于优秀分,talent低于优秀分称作nobleman,两者均低于优秀分,且virtue高于talent则称作foolman,其他的称作small man,按照总分对这四类人排序,且sage,nobleman, foolman,smallman的优先级依次降低。 总分相同的情况下按照virtue排序, 依然相同的情况下按照名字排序
思路:构建一个struct node记录考生的virute,talent, id, total 和rank(优先级); 在输入数据的时候,确定学生的优先级和总分,把每符合要求的学生添加vector<node> v中, 对v进行排序后输出;
注意点:foolman的评定标准是virtue,talent分数低于优秀分,并且virtue>=talent,而不是virtue>talent
 
 1 #include<iostream>
 2 #include<algorithm>
 3 #include<vector>
 4 using namespace std;
 5 struct node{
 6   int id, v, t, rank, total;
 7 };
 8 
 9 bool cmp(node a, node b){
10   if(a.rank!=b.rank) return a.rank>b.rank;
11   if(a.total!=b.total) return a.total>b.total;
12   if(a.v!=b.v) return a.v>b.v;
13   return a.id<b.id;
14 }
15 int main(){
16   int n, low, high, i;
17   cin>>n>>low>>high;
18   node temp;
19   vector<node> v;
20   for(i=0; i<n; i++){
21     scanf("%d %d %d", &temp.id, &temp.v, &temp.t);
22     if(temp.v>=low && temp.t>=low){
23       temp.total=temp.t+temp.v;
24       if(temp.v>=high&&temp.t>=high) temp.rank=4;
25       else if(temp.v>=high) temp.rank=3;
26       else if(temp.v>=temp.t) temp.rank=2;
27       else temp.rank=1;
28       v.push_back(temp);
29     }
30   }
31   sort(v.begin(), v.end(), cmp);
32   cout<<v.size()<<endl;
33   for(i=0; i<v.size(); i++)
34   printf("%08d %d %d\n", v[i].id, v[i].v, v[i].t);
35   return 0;
36 }

猜你喜欢

转载自www.cnblogs.com/mr-stn/p/9174355.html