题目描述
分析
一个简单的排序题,只是要考虑几种类别要分开放还是放在一起的问题。考虑到分开放比较麻烦,直接放在一起用flag表示类别即可。也尝试过将四种类别分开放到不同的vector里面,算法效率会稍微高一些。
AC代码
#include<iostream>
#include<string>
#include<vector>
#include<queue>
#include<algorithm>
using namespace std;
struct node {
int id, virtue, talent, total, flag;
}no[100005];
bool cmp(node a, node b) {
if (a.flag != b.flag) return a.flag < b.flag;
else if (a.total != b.total) return a.total > b.total;
else if(a.virtue!=b.virtue) return a.virtue > b.virtue;
else return a.id < b.id;
}
int main() {
#ifdef ONLINE_JUDGE
#else
freopen("1.txt", "r", stdin);
#endif
int n, L, h, cnt=0; cin >> n >> L >> h;
while (n--) {
int id, v, t;
scanf("%d%d%d", &id, &v, &t);
if (v >= L && t >= L) {
if (v >= h && t >= h) no[cnt++] = { id,v,t,v + t,1 };
else if (v >= h && t < h) no[cnt++] = { id,v,t,v + t,2 };
else if (v < h&&t < h&&v>=t) no[cnt++] = { id,v,t,v + t,3 };
else no[cnt++] = { id,v,t,v + t,4 };
}
}
cout << cnt << endl;
sort(no, no + cnt, cmp);
for (int i = 0; i < cnt;i++) {
printf("%08d %d %d\n", no[i].id, no[i].virtue, no[i].talent);
}
return 0;
}