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 applicant will have to provide two grades: the national entrance exam grade GE, and the interview grade GI. The final grade of an applicant is (GE + GI) / 2. The admission rules are:

  • The applicants are ranked according to their final grades, and will be admitted one by one from the top of the rank list.
  • If there is a tied final grade, the applicants will be ranked according to their national entrance exam grade GE. If still tied, their ranks must be the same.
  • Each applicant may have K choices and the admission will be done according to his/her choices: if according to the rank list, it is one‘s turn to be admitted; and if the quota of one‘s most preferred shcool is not exceeded, then one will be admitted to this school, or one‘s other choices will be considered one by one in order. If one gets rejected by all of preferred schools, then this unfortunate applicant will be rejected.
  • If there is a tied rank, and if the corresponding applicants are applying to the same school, then that school must admit all the applicants with the same rank, even if its quota will be exceeded.

Input Specification:

Each input file contains one test case. Each case starts with a line containing three positive integers: N (<=40,000), the total number of applicants; M (<=100), the total number of graduate schools; and K (<=5), the number of choices an applicant may have.

In the next line, separated by a space, there are M positive integers. The i-th integer is the quota of the i-th graduate school respectively.

Then N lines follow, each contains 2+K integers separated by a space. The first 2 integers are the applicant‘s GE and GI, respectively. The next K integers represent the preferred schools. For the sake of simplicity, we assume that the schools are numbered from 0 to M-1, and the applicants are numbered from 0 to N-1.

Output Specification:

For each test case you should output the admission results for all the graduate schools. The results of each school must occupy a line, which contains the applicants‘ numbers that school admits. The numbers must be in increasing order and be separated by a space. There must be no extra space at the end of each line. If no applicant is admitted by a school, you must output an empty line correspondingly.

Sample Input:

11 6 3
2 1 2 2 2 3
100 100 0 1 2
60 60 2 3 5
100 90 0 3 4
90 100 1 2 0
90 90 5 1 3
80 90 1 0 2
80 80 0 1 2
80 80 0 1 2
80 70 1 3 2
70 80 1 2 3
100 100 0 2 4

Sample Output:

0 10
3
5 6 7
2 8

1 4
  1 #include <iostream>
  2 #include <vector>
  3 #include <algorithm>
  4 #include <bitset>
  5
  6 using namespace std;
  7
  8 struct Applicant
  9 {
 10     int id;
 11     int EGrade;
 12     int IGrade;
 13     double final;
 14     int choice[6];
 15     int rank;
 16 };
 17
 18 Applicant applicants[40000];
 19
 20 bool cmp(const Applicant& lhs, const Applicant& rhs)
 21 {
 22     if (lhs.final == rhs.final)
 23         return lhs.EGrade > rhs.EGrade;
 24     return lhs.final > rhs.final;
 25 }
 26
 27 int main()
 28 {
 29     int applicantNum, schoolNum, choiceNum;
 30     cin >> applicantNum >> schoolNum >> choiceNum;
 31     int quota[100];
 32     for (int i = 0; i < schoolNum; i++)
 33         cin >> quota[i];
 34     for (int i = 0; i < applicantNum; i++)
 35     {
 36         applicants[i].id = i;
 37         cin >> applicants[i].EGrade >> applicants[i].IGrade;
 38         applicants[i].final = (applicants[i].EGrade + applicants[i].IGrade) / 2.0;
 39         for (int j = 0; j < choiceNum; j++)
 40             cin >> applicants[i].choice[j];
 41     }
 42     sort(applicants, applicants + applicantNum, cmp);
 43     //set the rank of the all applicants
 44     int final=0, EGrade=0, rank = 1;
 45     for (int i = 0; i < applicantNum; i++)
 46     {
 47         if (applicants[i].final == final&&applicants[i].EGrade == EGrade)
 48             applicants[i].rank = rank;
 49         else
 50         {
 51             final = applicants[i].final;
 52             EGrade = applicants[i].EGrade;
 53             rank = i + 1;
 54             applicants[i].rank = rank;
 55         }
 56     }
 57     bitset<100000> empty;
 58     vector<int> vec[100];
 59     for (int i = 0; i < schoolNum; i++)
 60         if (quota[i] <= 0)
 61             empty.set(i);
 62     int i = 0;
 63     rank = 1;
 64     while (1)
 65     {
 66         //admit the applicants with same rank
 67         while (i < applicantNum&&applicants[i].rank == rank)
 68         {
 69             for (int j = 0; j < choiceNum; j++)
 70             {
 71                 if (!empty[applicants[i].choice[j]])
 72                 {
 73                     quota[applicants[i].choice[j]]--;
 74                     vec[applicants[i].choice[j]].push_back(applicants[i].id);
 75                     break;
 76                 }
 77             }
 78             i++;
 79         }
 80         if (i == applicantNum)
 81             break;
 82         else
 83             rank = applicants[i].rank;    //next rank
 84
 85         for (int j = 0; j < schoolNum; j++)
 86             if (quota[j] <= 0)
 87                 empty.set(j);
 88     }
 89     for (int i = 0; i < schoolNum; i++)
 90     {
 91         sort(vec[i].begin(), vec[i].end());
 92         for (int j = 0; j < vec[i].size(); j++)
 93         {
 94             cout << vec[i][j];
 95             if (j < vec[i].size() - 1)
 96                 cout << " ";
 97         }
 98         cout << endl;
 99     }
100 }
				
时间: 2024-11-17 23:47:48

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

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(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) 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: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

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