1080. Graduate Admission (30)

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cstdlib>
using namespace std;

struct stu
{
  int GE;
  int GI;
  int score;
  int ranks;
  int id;
  int choices[6];
}App[40010];

struct school
{
  int quota;
  int stuNum;
  int best;
  int id[40010];
}Schools[110];
bool cmp(stu a,stu b)
{
  if(a.score != b.score) return a.score>b.score;
  else return a.GE>b.GE;
}
int main()
{
  int N=0,M=0,K=0;
  int i=0,j=0,temp=0,x=0,y=0,z=0;
   
  scanf("%d%d%d",&N,&M,&K);
  for(i=0; i<M; i++)
  {
    scanf("%d",&temp);
    Schools[i].quota = temp;
  }
  for(j=0; j<N; j++)
  {
    scanf("%d%d",&App[j].GE,&App[j].GI);
    App[j].score = (App[j].GE + App[j].GI)/2;
    App[j].id = j;
    for(i=0; i<K; i++)
    {
      scanf("%d",&App[j].choices[i]);
    }
  }
  sort(App, App+N, cmp);
  App[0].ranks = 1;
  for(i=1; i<N; i++)
  {
    if(App[i].score == App[i-1].score && App[i].GE == App[i-1].GE)
      App[i].ranks = App[i-1].ranks;
    else
      App[i].ranks = i+1;
  }
  
  for(i=0; i<N; i++)
  {
    for(j=0; j<K; j++)
    {
      x = App[i].choices[j];
      if(Schools[x].stuNum < Schools[x].quota || Schools[x].best == App[i].ranks)  //没招满,或者有同样优秀的人
      {
        y = Schools[x].stuNum;
        Schools[x].id[y] = App[i].id;          //在数组里存储录取的学号
        Schools[x].stuNum += 1;                //录取人数加1
        Schools[x].best = App[i].ranks;
        break;                                 //录取了一个,跳出循环
      }
    }
  }
  for(i=0; i<M; i++)
  {
    if(Schools[i].stuNum!=0)
    {
      sort(Schools[i].id,Schools[i].id+Schools[i].stuNum);
      for(j=0; j<Schools[i].stuNum; j++)
      {    
        if(j==0)
          printf("%d",Schools[i].id[j]);
        else
          printf(" %d",Schools[i].id[j]);
      }
    }
    printf("\n");
  }
  return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值