1080 Graduate Admission
作者:互联网
#include <iostream>
#include <string.h>
#include <algorithm>
#include <cstdio>
using namespace std;
struct student {
int id;
int GE;
int GI;
int avl;
int choices[10];
int Rank;
}stu[100010];
struct school{
int students[100];
int num;
}sch[110];
bool cmp(student a,student b)
{
if(a.avl!=b.avl) return a.avl>b.avl;
else if(a.GE!=b.GE) return a.GE>b.GE;
}
bool cmp1(int a,int b)
{
if(a!=b) return a<b;
}
int main()
{
freopen("C:\\Users\\KEKE\\Desktop\\test.txt","r",stdin);
for(int i=0;i<100010;i++)
{
stu[i].avl=0;
}
int n,m,k;
scanf("%d%d%d",&n,&m,&k);
int s[100];
for(int i=0;i<m;i++)
{
scanf("%d",&s[i]);
}
for(int i=0;i<n;i++)
{
stu[i].id=i;
scanf("%d %d",&stu[i].GE,&stu[i].GI);
stu[i].avl=stu[i].GE+stu[i].GI;
for(int j=0;j<k;j++)
{
scanf("%d",&stu[i].choices[j]);
}
}
for(int i=0;i<m;i++)
{
sch[i].num=0;
}
sort(stu,stu+n,cmp);
stu[0].Rank=1;
for(int i=1;i<n;i++)
{
if(stu[i].avl<stu[i-1].avl)
{
stu[i].Rank=i+1;
}
else if(stu[i].avl==stu[i-1].avl)
{
if(stu[i].GE<stu[i-1].GE)
stu[i].Rank=i+1;
else
stu[i].Rank=stu[i-1].Rank;
}
}
for(int i=0;i<n;i++)
{
for(int j=0;j<k;j++)
{
int schild=stu[i].choices[j];//当前学生的志愿学校
if(sch[schild].num<s[schild]||(stu[i].Rank==stu[sch[schild].students[sch[schild].num-1]].Rank))//学校没满
{
sch[schild].students[sch[schild].num]=stu[i].id;
sch[schild].num++;
break;
}
}
}
for(int i=0;i<m;i++)
{
if(sch[i].num==0)
{
printf("\n");
}
else
{
sort(sch[i].students,sch[i].students+sch[i].num,cmp1);
printf("%d",sch[i].students[0]);
for(int j=1;j<sch[i].num;j++)
{
printf(" %d",sch[i].students[j]);
}
printf("\n");
}
}
}
标签:sch,1080,int,Admission,Graduate,avl,stu,GE,num 来源: https://blog.csdn.net/qq_45557601/article/details/114001240