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

来源:互联网 发布:西安少儿编程培训机构 编辑:程序博客网 时间:2024/06/18 14:39

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 32 1 2 2 2 3100 100 0 1 260 60 2 3 5100 90 0 3 490 100 1 2 090 90 5 1 380 90 1 0 280 80 0 1 280 80 0 1 280 70 1 3 270 80 1 2 3100 100 0 2 4
Sample Output:
0 1035 6 72 81 4


题意:给你n个人的笔试和面试成绩,最终成绩为两个成绩的平均值,所有人按最终成绩排序,若最终成绩相同按笔试成绩排序,若仍相同,则两个人排名相同。每个人有k个志愿,按志愿录取,若这个学校未招满则可录取,同名次的若被录取学校相同,则该学校要录取同名次的所有学生(即使招满)

解题思路:先将n个人排序,然后将第一个人录取,后面的人一个个模拟下去,若名次和前一个人一样,志愿和前一个人录取学校一样,则直接录取



#include <iostream>#include <cstdio>#include <cstring>#include <string>#include <algorithm>#include <cmath>#include <map>#include <set>#include <stack>#include <queue>#include <vector>#include <bitset>using namespace std;#define LL long longconst int INF = 0x3f3f3f3f;struct node{    int s1,s2,s3,id;    int a[15];    friend bool operator <(node a,node b)    {        if(a.s3!=b.s3) return a.s3>b.s3;        else return a.s1>b.s1;    }} x[40008];int n,m,k,cnt[105],vis[105],ans[40008];vector<int>g[400009];int main(){    while(~scanf("%d%d%d",&n,&m,&k))    {        for(int i=0; i<m; i++) scanf("%d",&cnt[i]),g[i].clear();        memset(vis,0,sizeof vis);        for(int i=1; i<=n; i++)        {            scanf("%d%d",&x[i].s1,&x[i].s2);            x[i].s3=(x[i].s1+x[i].s2)/2;            for(int j=1; j<=k; j++) scanf("%d",&x[i].a[j]);            x[i].id=i-1;        }        sort(x+1,x+1+n);        g[x[1].a[1]].push_back(x[1].id);        ans[x[1].id]=x[1].a[1];        vis[x[1].a[1]]++;        for(int i=2; i<=n; i++)        {            for(int j=1; j<=k; j++)            {                if(cnt[x[i].a[j]]>vis[x[i].a[j]])                {                    g[x[i].a[j]].push_back(x[i].id);                    ans[x[i].id]=x[i].a[j];                    vis[x[i].a[j]]++;                    break;                }                if(ans[x[i-1].id]==x[i].a[j]&&x[i].s1==x[i-1].s1&&x[i].s3==x[i-1].s3)                {                    g[x[i].a[j]].push_back(x[i].id);                    ans[x[i].id]=x[i].a[j];                    vis[x[i].a[j]]++;                    break;                }            }        }        for(int i=0;i<m;i++) sort(g[i].begin(),g[i].end());        for(int i=0;i<m;i++)        {            int Size=g[i].size();            if(Size) printf("%d",g[i][0]);            for(int j=1;j<Size;j++) printf(" %d",g[i][j]);            printf("\n");        }    }    return 0;}

原创粉丝点击