PAT A1080(26分)

想不明白测试点1和2为什么过不了,逻辑跟参考程序一样,结构用的不一样。求好心人瞄一眼,提点迷津。

题目:https://pintia.cn/problem-sets/994805342720868352/problems/994805387268571136

#include <cstdio>
#include <algorithm>
using namespace std;
struct student{
	int GE, GI;
	int prefer[6];
	int id;
}stu[40010];
bool cmp(student a, student b){
	if (a.GE + a.GI != b.GE + b.GI) 
		return a.GE + a.GI > b.GE + b.GI;
	else
		return a.GE > b.GE;
}
int school[110][40010];
int main(){
	int n, m, k, num[110], quota[110];
	scanf("%d%d%d", &n, &m, &k);
	for(int i = 0; i < m; i++){
		scanf("%d", quota+i);
		num[i] = 0;
	}
	for(int i = 0; i < n; i++){
		scanf("%d%d", &stu[i].GE, &stu[i].GI);
		for(int j = 0; j < k; j++)
			scanf("%d", stu[i].prefer+j);
		stu[i].id = i;
	}
	sort(stu, stu + n, cmp);
	for(int i = 0; i < n; i++){
		for(int j = 0; j < k; j++){
			if(quota[stu[i].prefer[j]] == 0){continue;}
			else if(num[stu[i].prefer[j]] < quota[stu[i].prefer[j]]){
				school[stu[i].prefer[j]][num[stu[i].prefer[j]]] = stu[i].id;
				num[stu[i].prefer[j]]++;
				break;
			}
			else if(stu[i].GI == stu[school[stu[i].prefer[j]][num[stu[i].prefer[j]] - 1]].GI && stu[school[stu[i].prefer[j]][num[stu[i].prefer[j]] - 1]].GE == stu[i].GE){
				school[stu[i].prefer[j]][num[stu[i].prefer[j]]] = stu[i].id;
				num[stu[i].prefer[j]]++;
				break;
			}
		}
	}
	for(int i = 0; i < m; i++){
		if(num[i] > 0){
			sort(school[i], school[i]+num[i]);
			for(int j = 0; j < num[i]; j++){
				printf("%d", school[i][j]);
				if(j < num[i] - 1)
					printf(" ");
			}
			printf("\n");
		}
	}
	return 0;
}

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 7
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 7
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值