PAT(甲级)渡劫(十五)-Graduate Admission(30)
![](https://i-blog.csdnimg.cn/blog_migrate/a297fbcf2fc93a01eaee86141be21992.png)
![](https://i-blog.csdnimg.cn/blog_migrate/eac2e0a36f358ae19c48fc7ea9983991.png)
![](https://i-blog.csdnimg.cn/blog_migrate/86acd58c04c24271f6f7c703efd62466.png)
代码如下:
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
using namespace std;
const int maxn = 40005;
const int maxschool = 105;
int quota[maxschool];
vector<int> res[maxschool];
int vis[maxschool][maxn];
struct Applicant{
int id;
int ranks;
int GE,GI;
float grades;
int choose[5];
bool operator < (const Applicant &tmp)const{
if(grades == tmp.grades){
return GE > tmp.GE;
}else{
return grades > tmp.grades;
}
}
}app[maxn];
int main(){
int n,m,k;
scanf("%d%d%d",&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);
for(int j = 0 ; j < k ; j++){
scanf("%d",&app[i].choose[j]);
}
app[i].id = i;
app[i].grades = (app[i].GE + app[i].GI)/2.0f;
}
sort(app,app+n);
int cnt = 0;
for(int i = 0 ; i < n ; i++){
app[i].ranks = ++cnt;
for(int j = i+1 ; j < n ; j++){
if(app[i].grades == app[j].grades && app[i].GE == app[j].GE){
app[j].ranks = cnt;
i++;
}
}
}
for(int i = 0 ; i < n ; i++){
int j;
for(j = 0 ; j < k ; j++){
int s = app[i].choose[j];
if(quota[s] > 0){
quota[s]--;
res[s].push_back(app[i].id);
vis[s][app[i].ranks] = 1;
break;
}else{
if(vis[s][app[i].ranks] == 1){
res[s].push_back(app[i].id);
break;
}
}
}
}
for(int i = 0 ; i < m ; i++){
int num = res[i].size();
if(num == 0){
printf("\n");
}else{
sort(res[i].begin(),res[i].end());
printf("%d",res[i][0]);
for(int j=1;j<num;j++){
printf(" %d",res[i][j]);
}
printf("\n");
}
}
return 0;
}
运行结果:
![](https://i-blog.csdnimg.cn/blog_migrate/b9153a46d07b2cd2a96a42d9cad11bcc.png)