A1062 Talent and Virtue

题目链接:https://pintia.cn/problem-sets/994805342720868352/problems/994805410555346944

这一题思路很清晰,就是结构体排序,但是要读懂题目,我开始以为小人是品德低于H,结果出现了很多错误。

for (int i = 0; i < N; i++) {
		person a;
		cin >> a.ID >> a.VG >> a.TG;
		if (a.VG < L || a.TG < L)
			continue;
		if (a.VG >= H && a.TG >= H)
			a.cluster = 1;		//sage
		else if (a.VG >= H)
			a.cluster = 2;		//nobleman
		else if (a.TG >= H)
			a.cluster = 4;		//small man
		else
			a.cluster = 3;		//fool man
		P[num_sort] = a;
		num_sort++;
	}

后来修改了就好了,下面是源码

#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
#include <cmath>
#include<stack>
#include<queue>
//A1062 Talent and Virtue (25 分)

using namespace std;
const int maxn = 100010;

typedef char ElemT;

struct person {
	int ID;
	int VG;		//Virtue_Grade 
	int TG;		//Talent_Grade
	int cluster=5;	//"1" is sage; "2" is nobleman; "3" is a "fool man; 
}P[maxn];

//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 talentand virtue are both not below this line will be ranked;
//and H(< 100), the higher line of qualification
int N, L, H;
bool cmp(person a, person b) {
	if (a.cluster != b.cluster)
		return a.cluster < b.cluster;
	if (a.VG + a.TG != b.VG + b.TG)
		return a.VG + a.TG > b.VG + b.TG;
	if (a.VG != b.VG)
		return a.VG > b.VG;
	return a.ID < b.ID;
}

int main() {
	cin >> N >> L >> H;
	int num_sort = 0;
	for (int i = 0; i < N; i++) {
		person a;
		cin >> a.ID >> a.VG >> a.TG;
		if (a.VG < L || a.TG < L)
			continue;
		if (a.VG >= H && a.TG >= H)
			a.cluster = 1;		//sage
		else if (a.VG >= H)
			a.cluster = 2;		//nobleman
		else if (a.TG > a.VG)
			a.cluster = 4;		//small man
		else
			a.cluster = 3;		//fool man
		P[num_sort] = a;
		num_sort++;
	}

	sort(P, P + num_sort, cmp);

	cout << num_sort << endl;
	for (int i = 0; i < num_sort; i++) {
		cout << P[i].ID << " " << P[i].VG << " " << P[i].TG << endl;
	}

	return 0;

}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值