题解 | #Graduate Admission#

Graduate Admission

https://www.nowcoder.com/practice/b1bf27f86ecd4a5d9720d9cdc00d178e

#include <bits/stdc++.h>
using namespace std;

priority_queue<int, vector<int>, greater<int> > output;
const int N = 40010;
int quota[110];

struct Applicant {
	int id, Ge, Gi, rank, select[10];
	double final; // 这里要注意把final定义为double类型,要不然会出错
	bool operator <(const Applicant &w) const {
		if (final != w.final) return final > w.final;
		else if (Ge != w.Ge) return Ge > w.Ge;
		else return Gi > w.Gi;
	}
} app[N];

struct RES {
	vector<int>applicant;
} res[110];

int main() {
	// freopen("input.txt", "r", stdin);
	int n, m, k;
	cin >> n >> m >> k;
	for (int i = 0; i < m; i++) scanf("%d", "a[i]);
	for (int i = 0; i < n; i++) {
		scanf("%d %d", &app[i].Ge, &app[i].Gi);
		app[i].final = (app[i].Ge + app[i].Gi) * 0.1 / 2;
		app[i].id = i;
		for (int j = 0; j < k; j++) scanf("%d", &app[i].select[j]);
	}
	sort(app, app + n);
	app[0].rank = 1;
	int cnt = 1;
	for (int i = 1; i < n; i++) {
		cnt++;
		if (app[i].final < app[i - 1].final) {
			app[i].rank = cnt;
		} else {
			if (app[i].Ge < app[i - 1].Ge) {
				app[i].rank = cnt;
			} else {
				if (app[i].Gi < app[i - 1].Gi) {
					app[i].rank = cnt;
				} else {
					app[i].rank = app[i - 1].rank;
				}
			}
		}
	}

	for (int i = 0; i < n; i++) {
		for (int j = 0; j < k; j++) {
			int choice = app[i].select[j]; // choice表示选择学校的编号
			if (quota[choice] > 0) {
				quota[choice]--;
				res[choice].applicant.push_back(i);
				break;
			} else {
				int target_rank = app[res[choice].applicant.back()].rank;
				if (app[i].rank == target_rank) {
					res[choice].applicant.push_back(i);
					break;
				}
			}
		}
	}

	for (int i = 0; i < m; i++) {
		for (auto x : res[i].applicant) {
			output.push(app[x].id);
		}
		while (!output.empty()) {
			cout << output.top() << " ";
			output.pop();
		}
		puts("");
	}
	return 0;
}

全部评论
快2025年了还在c佳佳
1 回复 分享
发布于 09-01 08:24 上海

相关推荐

球球别再泡了:坏,我单9要了14
点赞 评论 收藏
分享
点赞 评论 收藏
分享
1 收藏 评论
分享
牛客网
牛客企业服务