#include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>
using namespace std;
struct student{
int id, Ge, Gi;
int choices[5];
};
bool compSt(student a, student b){
if(a.Ge + a.Gi != b.Ge + b.Gi)
return a.Ge + a.Gi > b.Ge + b.Gi;
return a.Ge > b.Ge;
}
bool compAp(int a, int b){
return a < b;
}
int main()
{
int N, M, K;
int quotas[100];
cin>>N>>M>>K;
vector<vector<int>> applicants(M);//记录每个学校的录取信息
vector<student> applications(N);
for(int i = 0; i < M; i++)
scanf("%d", &(quotas[i]));
for(int i = 0; i < N; i++){
scanf("%d %d", &(applications[i].Ge), &(applications[i].Gi));
applications[i].id = i;
for(int j = 0; j < K; j++)
scanf("%d", &((applications[i].choices)[j]));
}
sort(applications.begin(), applications.end(), compSt);
bool tie_record[100] = {false};
int tie_Gt = -1, tie_Ge = -1;
for(auto app = applications.begin(); app != applications.end(); app ++){
if(app -> Ge + app -> Gi != tie_Gt || app -> Ge != tie_Ge){
memset(tie_record, false, sizeof(bool) * 100);
tie_Gt = app -> Ge + app -> Gi;
tie_Ge = app -> Ge;
}
for(int i = 0; i < K; i++){
if(tie_record[app->choices[i]] || quotas[app->choices[i]] > 0){
quotas[app->choices[i]] --;
tie_record[app->choices[i]] = true;
applicants[app->choices[i]].push_back(app->id);
break;
}
}
}
for(auto school = applicants.begin(); school != applicants.end(); school ++){
sort(school->begin(), school->end(), compAp);
for(auto itr = school->begin(); itr != school->end(); itr++){
printf("%d", *itr);
if(school->end() - itr > 1)
printf(" ");
}
printf("\n");
}
}
用LUA(和C++)刷PAT (Advanced Level) ——1080 Graduate Admission
这段代码实现了一个模拟大学录取过程的程序。它首先读取学生信息和学校配额,然后根据学生的总成绩进行排序。接着,按照成绩优先级分配学生到他们首选的学校,直到所有名额分配完毕。最后,输出每个学校录取的学生ID。程序使用了C++标准库中的排序和数据结构功能。
摘要由CSDN通过智能技术生成