PAT:1080. Graduate Admission (30) AC

#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;

struct Student
{
  int GE,GI,sum,rank,ID;
  int prefer[6];
}STU[40066];

struct School
{
  int want;        //各学校招生人数
  int get;        //已招到的人数
  int line;        //最后一名进来的排名线
  int queue[40066];      //已投档学生编号
}SC[106];

bool cmp(Student a,Student b)
{
  if(a.sum!=b.sum)
    return a.sum>b.sum;
  else
    return a.GE>b.GE;
}

int main()
{
  memset(STU,0,sizeof(STU));
  memset(SC,0,sizeof(SC));
  int n,m,k;              //n名考生,m所学校,k个志愿
  scanf("%d%d%d",&n,&m,&k);
  for(int i=0 ; i<m ; ++i)      //输入各学校招生人数
    scanf("%d",&SC[i].want);
  for(int i=0 ; i<n ; ++i)
  {
    scanf("%d %d",&STU[i].GE, &STU[i].GI);    //填入分数
    STU[i].sum=STU[i].GE+STU[i].GI;        //填入总分
    STU[i].ID=i;                //填入编号
    for(int j=0 ; j<k ; ++j)
    {
      int tmp=-1;
      scanf("%d",&tmp);      //填入志愿
      STU[i].prefer[j]=tmp;
    }
  }
  sort(STU,STU+n,cmp);
  STU[0].rank=1;
  for(int i=1 ; i<n ; ++i)            //填入排序
  {
    if(STU[i].sum==STU[i-1].sum && STU[i].GE==STU[i-1].GE)
      STU[i].rank=STU[i-1].rank;
    else
      STU[i].rank=i+1;
  }
  //学生志愿为导向
  for(int i=0 ; i<n ; ++i)
  {
    for(int j=0 ; j<k ; ++j)      //STU[i].prefer[j]代表考生的j号志愿学校代码
    {
      if(SC[STU[i].prefer[j]].want>SC[STU[i].prefer[j]].get ||  SC[STU[i].prefer[j]].line==STU[i].rank )  //该校未招满或者已招满但考生排名和最后一个找入学生一样
      {
      SC[STU[i].prefer[j]].queue[SC[STU[i].prefer[j]].get]=STU[i].ID;        //考生i的ID入档
        ++SC[STU[i].prefer[j]].get;              //入档学生数+1
        SC[STU[i].prefer[j]].line=STU[i].rank;          //更新最后名次
    break;      //已被录取
      }
    }
  }
  //输出
  for(int i=0 ; i<m ; ++i)
  {
    sort(SC[i].queue,SC[i].queue+SC[i].get);    //最后升序排列
    for(int j=0 ; j<SC[i].get ;++j)
    {
      printf("%d",SC[i].queue[j]);
      if(j!=SC[i].get-1)
        printf(" ");
    }
    printf("\n");
  }
  return 0;
}
时间: 2024-07-29 16:59:16

PAT:1080. Graduate Admission (30) AC的相关文章

PAT:1080. Graduate Admission (30) 全错

#include<stdio.h> #include<string.h> #include<algorithm> using namespace std; struct Student { int GE,GI,sum,rank,ID; int prefer[6]; }STU[40066]; struct School { int want; //各学校招生人数 int get; //已招到的人数 int line; //最后一名进来的排名线 int queue[4006

PAT:1080. Graduate Admission (30) 部分错误(录取以学校为导向而不是考生志愿为导向导致的错误)

#include<stdio.h> #include<string.h> #include<algorithm> using namespace std; int want[106]; //各学校招生人数 struct Student { int GE,GI,sum,rank,ID; int prefer[6]; bool R; //代表该生录取情况 }STU[40066]; bool cmp(Student a,Student b) { if(a.sum!=b.sum

PAT(A) 1080. Graduate Admission (30)

It is said that in 2013, there were about 100 graduate schools ready to proceed over 40,000 applications in Zhejiang Province. It would help a lot if you could write a program to automate the admission procedure. Each applicant will have to provide t

PAT 1080. Graduate Admission (30)

1080. Graduate Admission (30) It is said that in 2013, there were about 100 graduate schools ready to proceed over 40,000 applications in Zhejiang Province. It would help a lot if you could write a program to automate the admission procedure. Each ap

1080. Graduate Admission (30)

1080. Graduate Admission (30) 时间限制 200 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue It is said that in 2013, there were about 100 graduate schools ready to proceed over 40,000 applications in Zhejiang Province. It would help a lot if yo

PAT (Advanced Level) 1080. Graduate Admission (30)

简单题. #include<cstdio> #include<cstring> #include<cmath> #include<vector> #include<map> #include<stack> #include<queue> #include<string> #include<iostream> #include<algorithm> using namespace std;

1080. Graduate Admission (30) (模拟排序啊 ZJU_PAT)

题目链接:http://www.patest.cn/contests/pat-a-practise/1080 It is said that in 2013, there were about 100 graduate schools ready to proceed over 40,000 applications in Zhejiang Province. It would help a lot if you could write a program to automate the adm

1080 Graduate Admission (30)(30 分)

It is said that in 2013, there were about 100 graduate schools ready to proceed over 40,000 applications in Zhejiang Province. It would help a lot if you could write a program to automate the admission procedure. Each applicant will have to provide t

PAT:1030. Travel Plan (30) AC

#include<stdio.h> #include<string.h> #include<algorithm> using namespace std; const int MAXV=510; const int INF=0x3fffffff; int N,M,S,D; //城市数,高速公路数,起点,终点 bool visit[MAXV]; //标记在迪杰斯特拉中是否遍历过 int GD[MAXV][MAXV]; //存储距离图 int GC[MAXV][MAXV];