题目链接:
题目描述:
(1)分数分为Ge和Gi两部分,按照总分给学生排名次,如果总分一样,则按照Ge来排;
(2)每个学生都有几个志愿,按照志愿高低给学生分配学校;
(3)对于名次一样又报了同一学校的学生,该学校只要接收了一个就得接收全部,即便超出了原定的招生名额;
题目分析:
每次模拟题写得总是很冗长的感觉啊。
需要注意的是写学校选学生那部分。
代码:
#include<iostream>
#include<vector>
#include<string.h>
#include<algorithm>
#include<set>
using namespace std;
struct Student{
int stuID;
int GE;
int GI;
int EI;
int rank;
vector<int> preferred;
};
bool operator <(const Student& stu1,const Student& stu2){
return stu1.EI == stu2.EI ? stu1.GE>stu2.GE:stu1.EI > stu2.EI;
}
struct School{
int quota;
int lowest;
set<int> admission;
};
int main()
{
int N, M, K;
scanf("%d%d%d",&N,&M,&K);
Student* graduates = new Student[N];
School* schools = new School[M];
for (int i = 0; i < M; i++){
scanf("%d",&schools[i].quota);
}
for (int i = 0; i < N; i++){
scanf("%d%d",&graduates[i].GE,&graduates[i].GI);
graduates[i].EI = graduates[i].GE + graduates[i].GI;
graduates[i].stuID = i;
int prefer;
for (int j = 0; j < K;j++){
scanf("%d",&prefer);
graduates[i].preferred.push_back(prefer);
}
}
sort(graduates,graduates+N);
for (int i = 0; i < N; i++){
if (i>0 && graduates[i].EI == graduates[i - 1].EI && graduates[i].GE == graduates[i - 1].GE){
graduates[i].rank = graduates[i - 1].rank;
}
else{
graduates[i].rank = i + 1;
}
for (int j = 0; j < K; j++){
int schID = graduates[i].preferred[j];
if (schools[schID].quota>0 || graduates[i].rank == schools[schID].lowest){
schools[schID].lowest = graduates[i].rank;
schools[schID].quota--;
schools[schID].admission.insert(graduates[i].stuID);
break;
}
}
}
for (int i = 0; i < M; i++){
if (schools[i].admission.empty()){
printf("\n");
}
else{
auto it = schools[i].admission.begin();
printf("%d",*it++);
for (;it!=schools[i].admission.end(); it++){
printf(" %d",*it);
}
printf("\n");
}
}
return 0;
}