题目大意
现在给出一些学生的id,品德分和才能分,要求将这些学生排序
- 参与排序学生的品德分和才能分必须都达到最低要求
- 如果品德分和才能分都大于等于所给的高分就判定为圣人
- 如果品德分大于等于所给高分大于才能分就判定为君子
- 如果品德分和才能分都低于所给高分,但是品德分大于等于才能分就判定为庸人
- 其他就判定为小人
- 排序规则:先有圣人>君子>庸人>小人,然后总分高的>总分低的, 之后品德分高的>品德分低的,最后是id小>id大的
输入
每组包含一个测试用例
- 第一行是三个正整数 N ≤ 1 0 5 N\leq10^5 N≤105表示学生总数, L ≥ 60 L\ge60 L≥60表示最低要求的分数, H < 100 H<100 H<100表示所给高分
- 之后有
N
N
N行,每行格式为
ID_Number Virtue_Grade Talent_Grade
,ID_Number
是一个八位数,所有的分数都在 [ 0 , 100 ] [0,100] [0,100]之间
输出
对每个测试用例,先在一行中输出
M
M
M表示共有多少人参与排序
然后有
M
M
M行输出排序后的学生,格式与输入一致
样例输入
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
样例输出
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
解析
按照题意将每个学生归类,然后在排序函数里面写好排序规则进行排序即可
python会超时
C++AC
python:
# -*- coding: utf-8 -*-
# @Time : 2019/6/24 13:57
# @Author : ValarMorghulis
# @File : 1062.py
import functools
class node:
def __init__(self, id, virtue, talent, tot, category):
self.id = id
self.virtue = virtue
self.talent = talent
self.tot = tot
self.category = category
def toString(self):
return "%s %d %d" % (self.id, self.virtue, self.talent)
def cmp(a, b):
if a.category != b.category:
return -1 if a.category < b.category else 1
if a.tot != b.tot:
return -1 if a.tot > b.tot else 1
if a.virtue != b.virtue:
return -1 if a.virtue > b.virtue else 1
return -1 if a.id < b.id else 1
def solve():
n, low, high = map(int, input().split())
a = list()
for i in range(n):
id, virtue, talent = input().split()
virtue, talent = int(virtue), int(talent)
if virtue >= low and talent >= low:
if virtue >= high and talent >= high:
a.append(node(id, virtue, talent, virtue + talent, 1))
elif virtue >= high > talent:
a.append(node(id, virtue, talent, virtue + talent, 2))
elif high > virtue >= talent and talent < high:
a.append(node(id, virtue, talent, virtue + talent, 3))
else:
a.append(node(id, virtue, talent, virtue + talent, 4))
a=sorted(a, key=functools.cmp_to_key(cmp))
print(len(a))
for i in a:
print(i.toString())
if __name__ == "__main__":
solve()
C++:
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<cstring>
#include<string>
#include<cmath>
#define inf 0xffffffff
using namespace std;
typedef struct node
{
int id, virtue, talent, tot, category;
};
bool cmp(node a, node b)
{
if(a.category!=b.category)
return a.category<b.category;
if(a.tot!=b.tot)
return a.tot>b.tot;
if(a.virtue!=b.virtue)
return a.virtue>b.virtue;
return a.id<b.id;
}
int main()
{
int n, low, high;
scanf("%d%d%d", &n, &low, &high);
vector<node> a;
for(int i=0; i<n; i++)
{
int id, virtue, talent;
scanf("%d%d%d", &id, &virtue, &talent);
if(virtue>=low&&talent>=low)
{
if(virtue>=high&&talent>=high)
{
node t;
t.id=id, t.virtue=virtue, t.talent=talent, t.tot=virtue+talent, t.category=1;
a.push_back(t);
}
else
if(virtue>=high&&talent<high)
{
node t;
t.id=id, t.virtue=virtue, t.talent=talent, t.tot=virtue+talent, t.category=2;
a.push_back(t);
}
else
if(virtue<high&&talent<high&&talent<=virtue)
{
node t;
t.id=id, t.virtue=virtue, t.talent=talent, t.tot=virtue+talent, t.category=3;
a.push_back(t);
}
else
{
node t;
t.id=id, t.virtue=virtue, t.talent=talent, t.tot=virtue+talent, t.category=4;
a.push_back(t);
}
}
}
int cnt=a.size();
sort(a.begin(), a.end(), cmp);
printf("%d\n", cnt);
for(int i=0; i<cnt; i++)
printf("%d %d %d\n", a[i].id, a[i].virtue, a[i].talent);
return 0;
}