AcWing 1548. 才华与德行
原题链接
简单
作者:
Value
,
2020-05-26 12:11:15
,
所有人可见
,
阅读 676
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
using namespace std;
const int N = 1E5 + 10;
struct node{
int id, moral, gift;
int rank;
};
int n, pass, good;
node stu[N];
int fitNum;
void read(){
cin >> n >> pass >> good;
fitNum = 0;
for(int i = 0; i < n; i ++ ){
scanf("%d%d%d", &stu[fitNum].id, &stu[fitNum].moral, &stu[fitNum].gift);
if(stu[fitNum].moral < pass || stu[fitNum].gift < pass) continue;
// 才华和德行均不低于 H 的是圣人
if(stu[fitNum].moral >= good && stu[fitNum].gift >= good) stu[fitNum].rank = 1;
// 才华低于 H,德行不低于 H 的是君子
else if(stu[fitNum].moral >= good && stu[fitNum].gift < good) stu[fitNum].rank = 2;
// 才华和德行均低于 H,但是德行不低于才华的是愚人
else if(stu[fitNum].moral < good && stu[fitNum].gift < good && stu[fitNum].moral >= stu[fitNum].gift){
stu[fitNum].rank = 3;
}else stu[fitNum].rank = 4;
// cout << stu[fitNum].rank << endl;
fitNum ++ ;
}
}
bool cmp(node a, node b){
if(a.rank != b.rank) return a.rank < b.rank;
// 圣人,君子们按德才总分不升序排序
if(a.moral + a.gift != b.moral + b.gift) return (a.moral + a.gift) > (b.moral + b.gift);
else{
// 如果出现总分相同的情况,则按德行分不升序排名
if(a.moral != b.moral) return a.moral > b.moral;
else return a.id < b.id;
}
}
int main(){
read();
sort(stu, stu + fitNum, cmp);
cout << fitNum << endl;
for(int i = 0; i < fitNum; i ++ ){
cout << stu[i].id << " " << stu[i].moral << " " << stu[i].gift << endl;
}
return 0;
}
多加一个rank标记,方便排序,妙~