zoukankan      html  css  js  c++  java
  • 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 和priority(优先级); 在输入数据的时候,确定学生的优先级和总分,把每符合要求的学生添加vector<node> v中, 对v进行排序后输出;
    注意点:foolman的评定标准是virtue,talent分数低于优秀分,并且virtue>=talent,而不是virtue>talent, 注意排序的规则, 是不低于 还是低于, 此外 在输入的时候就可以筛选不合格数的数据
     
     1 #include<iostream>
     2 #include<vector>
     3 #include<algorithm>
     4 using namespace std;
     5 struct Node{
     6   int talnet, virtue, total, priority;
     7   int id;
     8 };
     9 
    10 bool cmp(Node& a, Node& b){
    11   if(a.priority!=b.priority) return a.priority<b.priority;
    12   if(a.total!=b.total) return a.total>b.total;
    13   if(a.virtue!=b.virtue) return a.virtue>b.virtue;
    14   return a.id<b.id;
    15 }
    16 int main(){
    17   int n, low, high, i;
    18   scanf("%d%d%d", &n,  &low, &high);
    19   vector<Node> v(n+1);
    20   int idx=0;
    21   for(i=0; i<n; i++){
    22     int id, talnet, virtue, priority=-1;
    23     scanf("%d%d%d", &id, &virtue, &talnet);
    24     //确定每个人的优先级, 优先级数越小 优先级越高
    25     if(virtue>=high && talnet>=high) priority=1;
    26     else if(virtue>=high && talnet>=low) priority=2;
    27     else if(virtue>=talnet && talnet>=low) priority = 3;
    28     else if(virtue>=low && talnet>=low) priority = 4;
    29     //优先级为-1表示至少有一个分数小于low
    30     if(priority!=-1){
    31       v[idx].id = id;
    32       v[idx].talnet = talnet;
    33       v[idx].virtue = virtue;
    34       v[idx].priority = priority;
    35       v[idx].total = virtue + talnet;
    36       idx++;
    37     }
    38   }
    39   sort(v.begin(), v.begin()+idx, cmp);
    40   printf("%d
    ", idx);
    41   for(i=0; i<idx; i++) printf("%08d %d %d
    ", v[i].id, v[i].virtue, v[i].talnet);
    42   return 0;
    43 }
    有疑惑或者更好的解决方法的朋友,可以联系我,大家一起探讨。qq:1546431565
  • 相关阅读:
    python 统计gitlab代码量
    whistle 模拟用户网络超时
    Node.js 快速转换 url 链接
    实用的 Git 命令
    前端常用 prettier 配置 + vetur 配置
    vue 项目 eslint + prettier 配置
    lodash 方法 debounce 防连点 防抖按钮点击
    npm 包实现自动登录 CICD 流程
    git push --follow-tags 命令
    小程序 iOS webview 中网页使用 iframe 无法滚动问题
  • 原文地址:https://www.cnblogs.com/mr-stn/p/9174355.html
Copyright © 2011-2022 走看看