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)
    return a.sum>b.sum;
  else
    return a.GE>b.GE;
}

int main()
{
  memset(STU,0,sizeof(STU));
  fill(want,want+106,-1);        //各学校招生人数初始设置-1
  int n,m,k;              //n名考生,m所学校,k个志愿
  scanf("%d%d%d",&n,&m,&k);
  for(int i=0 ; i<m ; ++i)      //输入各学校招生人数
    scanf("%d",&want[i]);
  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[tmp]=1;
    }
  }
  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<m ; ++i)            //输出各学校录取信息
  {
    int top=0;                  //用于输出并列排名的破格录取
    int kongge=0;                //控制空格的输出
    for(int j=0 ; j<n ; ++j)
    {
      if(STU[j].R==0 && STU[j].prefer[i]==1 && (want[i]>0 || want[i]==0 && STU[j].rank==top))  //该生未被录取,该生报考这个学校,该校还招人;或者学校招满,只招并列此名次的同学
      {
        if(kongge!=0)
          printf(" ");
        printf("%d",STU[j].ID);
        kongge=1;
        top=STU[j].rank;          //记录该考生的排名
        STU[j].R=1;              //标记考生已投档
        --want[i];              //招生需求人数-1
      }
    }
    printf("\n");
  }

  return 0;
}
时间: 2024-11-10 12:54:00

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

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: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[4006

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 (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;

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

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

pat1080. 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