其他分享
首页 > 其他分享> > PAT A1080(部分测试点无法通过)

PAT A1080(部分测试点无法通过)

作者:互联网

#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;

const int maxn = 40010;

struct Stu{
	int id, ge, gi, total, rankPos;
	int pre[6];
}stu[maxn];

vector<int> school;
vector<int> admit[100];

bool cmp(Stu a, Stu b) {
	if(a.total != b.total) return a.total > b.total;
	else if(a.ge != b.ge) return a.ge > b.ge;
}

int main() {
	int n, m, k;
	cin >> n >> m >> k;
	for(int i=0;i<m;i++) {
		int temp;
		cin >> temp;
		school.push_back(temp);
	}
	for(int i=0; i<n; i++) {
		stu[i].id = i;
		cin >> stu[i].ge >> stu[i].gi;
		stu[i].total = stu[i].ge + stu[i].gi;
		for(int j=0; j<k; j++) {
			cin >> stu[i].pre[j];
		}
	}
	sort(stu, stu+n, cmp);
	stu[0].rankPos = 1;
	for(int i=1;i<n;i++) {
		stu[i].rankPos = i+1;
		if(stu[i].ge == stu[i-1].ge && stu[i].total == stu[i-1].total) {
			stu[i].rankPos = stu[i-1].rankPos;
		}
	}
	
	for(int i=0; i<n; i++) {
		for(int j=0; j<k; j++) {
			if(school[stu[i].pre[j]] > 0) {
				admit[stu[i].pre[j]].push_back(stu[i].id);
				school[stu[i].pre[j]] --;
				break;
			} else {
				int lastId, admitSize;
				admitSize = admit[stu[i].pre[j]].size();
				if(admitSize) {
					lastId = admit[stu[i].pre[j]][admitSize-1];
					if(stu[i].rankPos == stu[lastId].rankPos) {
						admit[stu[i].pre[j]].push_back(stu[i].id);
						school[stu[i].pre[j]]--;
						break;
					}
				}
			}
		}
	}
	for(int i=0; i<m; i++) {
		if(admit[i].size()) {
			sort(admit[i].begin(), admit[i].end());
			for(int j=0; j < admit[i].size(); j++) {
				if(j) printf(" ");
				printf("%d", admit[i][j]);
			}
		}
		if(i!=m-1) printf("\n");
	}
	
	return 0;
} 

测试点1,2,4不过???????

标签:pre,PAT,测试点,int,A1080,ge,stu,admit,total
来源: https://blog.csdn.net/qq_29948297/article/details/112626724