PAT 1080. Graduate Admission (30)(志愿录取,排序,rank)

来源:互联网 发布:非常好的绘画软件 编辑:程序博客网 时间:2024/04/27 01:40

官网

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 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.大约100个学校,超过40,000个申请书,写个程序来录取学生。
  • 2.以总分数来排名,如果相同则看GE分数,如果GE也相同(总共看俩门成绩)则排名一致。
  • 3.每个申请人有k个选择,如果这个学校没满,那么他将被录取,但是如果他申请的这个学校,最后一个的排名跟他一样,尽管已经超名额了,他也将被录取,否则看下一个志愿,如果所有志愿都被刷,他么他将被刷。
  • 4.输出时,第i行如果没有学生则哪一行为空。

解题思路

  • 1.先排序,再排名,排名的时候就可以录取学生了,更新每个学校的余额以及最后一个学生的rank就可以了。

AC代码

#include<iostream>#include<vector>#include<algorithm>using namespace std;int n, m,k;int quota[101],have[101],last_rank[101];struct student{    int id,ge, gi,total,rank;    int preferred[6];};bool cmp(const student &a, const student &b){    if (a.total != b.total)    {        return a.total > b.total;    }    else if (a.ge != b.ge)    {        return a.ge > b.ge;    }    else{        //这里为啥return true会报错        return false;    }}student stu[40000];vector<int> admission[101];int main(){    cin >> n >> m >> k;    for (int i = 0; i < m; i++)    {        cin >> quota[i];    }    for (int i = 0; i < n; i++)    {        cin >> stu[i].ge >> stu[i].gi;        for (int j = 0; j < k; j++)        {            cin >> stu[i].preferred[j];        }        stu[i].total = stu[i].ge + stu[i].gi;        stu[i].id = i;    }    sort(stu, stu + n, cmp);    for (int i = 0; i < n; i++)    {        //排名        if (i==0)        {            stu[i].rank = 1;        }        else{            if (stu[i].total == stu[i-1].total && stu[i].ge == stu[i-1].ge)            {                stu[i].rank = stu[i - 1].rank;            }            else            {                stu[i].rank = i + 1;            }        }        //看学校        for (int j = 0; j < k; j++)        {            //如果名额没满,并且那个学校的最后一个排名相同,则录取            int chooce = stu[i].preferred[j];            if (have[chooce]<quota[chooce]||last_rank[chooce]==stu[i].rank)            {                have[chooce]++;                admission[chooce].push_back(stu[i].id);                last_rank[chooce] = stu[i].rank;                break;            }        }    }    //输出    for (int i = 0; i < m; i++)    {        ;        if (!admission[i].empty())        {            sort(admission[i].begin(), admission[i].end());            for (int j = 0; j < admission[i].size(); j++)            {                ;                if (j==0)                {                    cout << admission[i][j];                }                else{                    cout << " " << admission[i][j];                }            }        }        cout << endl;    }    return 0;}
0 0
原创粉丝点击