本文主要是介绍1080. Graduate Admission 解析,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
录取的问题。
先给各个成绩进行排序,然后给出排名。
排名相同的,可以超额。
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstring>#define MAX 110using namespace std;int n, m, k;struct appNode {int id;int ge;int gi;int gfin;int rank;vector <int> choice;
};
vector <appNode> list;
int school[MAX];bool cmp(appNode a1, appNode a2) {if (a1.gfin != a2.gfin) {return a1.gfin > a2.gfin;}else if (a1.gfin == a2.gfin && a1.ge != a2.ge) {return a1.ge > a2.ge;}elsereturn a1.choice < a2.choice;
}int main() {cin >> n >> m >> k;for (int i = 0; i < m; i++) {cin >> school[i];}list.resize(n);for (int i = 0; i < n; i++) {scanf("%d%d", &list[i].ge, &list[i].gi);list[i].id = i;list[i].gfin = list[i].ge + list[i].gi;int tchoice;for (int j = 0; j < k; j++) {scanf("%d", &tchoice);list[i].choice.push_back(tchoice);}}sort(list.begin(), list.end(), cmp);int NowRank = 1;list[0].rank = NowRank;int pre = 0;for (int i = 1; i < list.size(); i++) {if (list[pre].gfin == list[i].gfin && list[pre].ge == list[i].ge) {list[i].rank = NowRank;}else {list[i].rank = ++NowRank;pre = i;}}vector <appNode> FinApp[MAX];vector <int> FinAns[MAX];for (int i = 0; i < list.size(); i++) {for (int j = 0; j < k; j++) {int c = list[i].choice[j];if (school[c] > 0) {//没录取满FinApp[c].push_back(list[i]);FinAns[c].push_back(list[i].id);school[c]--;break;}else {//满了int last = FinApp[c].size() - 1;if (FinApp[c][last].rank == list[i].rank) {//排名相同录取FinApp[c].push_back(list[i]);FinAns[c].push_back(list[i].id);break;}}}}for (int i = 0; i < m; i++) {if (FinAns[i].size() != 0) {sort(FinAns[i].begin(), FinAns[i].end());cout << FinAns[i][0];for (int j = 1; j < FinAns[i].size(); j++) {cout << " " << FinAns[i][j];}cout << endl;}elsecout << endl;}return 0;
}
这篇关于1080. Graduate Admission 解析的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!