其他分享
首页 > 其他分享> > 1080 Graduate Admission

1080 Graduate Admission

作者:互联网

有个段错误

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
#define maxn 40010
int N, K, M; 
struct node{
	int ind, ge, gi, gf, ch[5]={0}, rank;
}stu[maxn];
bool cmp(node a, node b){
	if(a.gf != b.gf) return a.gf > b.gf;
	else if(a.ge != b.ge) return a.ge > b.ge;
}
int main(){
	scanf("%d %d %d", &N, &M, &K);
	int sch[M];
	for(int i = 0; i < M; i++) scanf("%d", &sch[i]);
	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].ch[j]);
		stu[i].ind = i;
		stu[i].gf = (int)(1.0 * (stu[i].ge + stu[i].gi) / 2 + 0.5);
	}
	sort(stu, stu + N, cmp);
	stu[0].rank = 1;
	for(int i = 1; i < N; i++){
		if(stu[i].gf != stu[i-1].gf) stu[i].rank = i + 1;
		else if(stu[i].ge != stu[i-1].ge) stu[i].rank = i + 1;
		else stu[i].rank = stu[i-1].rank;
	}
	int prerank = -1, presch = -1;
	vector<int> v[M]; 
	for(int i = 0; i < N; i++){
		for(int j = 0; j < K; j++){
			if(sch[stu[i].ch[j]] > 0){
				sch[stu[i].ch[j]]--;
				v[stu[i].ch[j]].push_back({stu[i].ind});
				presch = stu[i].ch[j];
				prerank = stu[i].rank;
				break;
			}
			else if(stu[i].ch[j] == presch && stu[i].rank == prerank){
				v[stu[i].ch[j]].push_back({stu[i].ind}); break;
			}
		}
	}
	for(int i = 0; i < M; i++){
		if(v[i].size() > 0){
			sort(v[i].begin(), v[i].end());
			for(int j = 0; j < v[i].size(); j++){
				printf("%s%d", j==0?"":" ", v[i][j]);
			}
		}
		printf("\n");
	}
	return 0;
}


J_北冥有鱼 发布了93 篇原创文章 · 获赞 0 · 访问量 543 私信 关注

标签:ch,gf,1080,int,Admission,rank,Graduate,stu,ge
来源: https://blog.csdn.net/weixin_35737222/article/details/103935933