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
 #include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
typedef struct{
int id;
int Ge;
int Gi;
int choice[];
int rank;
int school;
}info;
bool cmp(info a, info b){
int suma = a.Ge + a.Gi, sumb = b.Ge + b.Gi;
if(suma != sumb)
return suma > sumb;
else return a.Ge > b.Ge;
}
bool cmp2(info a, info b){
if(a.school != b.school)
return a.school < b.school;
else
return a.id < b.id;
}
info stu[];
int main(){
int N, M, K, quota[];
scanf("%d%d%d", &N, &M, &K);
for(int i = ; i < M; i++)
scanf("%d", &quota[i]);
for(int i = ; i < N; i++){
stu[i].id = i;
stu[i].school = -;
scanf("%d%d", &stu[i].Ge, &stu[i].Gi);
for(int j = ; j < K; j++)
scanf("%d", &stu[i].choice[j]);
}
sort(stu, stu + N, cmp);
stu[].rank = ;
stu[].school = stu[].choice[];
quota[stu[].school]--;
for(int i = ; i < N; i++){
if(stu[i].Ge + stu[i].Gi == stu[i - ].Ge + stu[i - ].Gi && stu[i].Ge == stu[i - ].Ge){
stu[i].rank = stu[i - ].rank;
}else{
stu[i].rank = i + ;
}
for(int j = ; j < K; j++){
if(quota[stu[i].choice[j]] > ){
stu[i].school = stu[i].choice[j];
quota[stu[i].choice[j]]--;
break;
}else if(quota[stu[i].choice[j]] <= && stu[i].choice[j] == stu[i - ].school && stu[i].rank == stu[i - ].rank){
stu[i].school = stu[i].choice[j];
quota[stu[i].choice[j]]--;
break;
}
}
}
sort(stu, stu + N, cmp2);
int index, cnt = ;
for(int i = ; i < N; i++){
index = i;
if(stu[i].school != -)
break;
}
while(cnt < stu[index].school){
printf("\n");
cnt++;
}
printf("%d", stu[index].id);
int temp = stu[index].school;
for(int i = index + ; i < N; i++){
if(stu[i].school == temp){
printf(" %d", stu[i].id);
}else{
temp = stu[i].school;
while(cnt < temp){
printf("\n");
cnt++;
}
printf("%d", stu[i].id);
}
}
while(cnt < M){
printf("\n");
cnt++;
}
cin >> N;
return ;
}

总结:

1、这道题模拟的是填报志愿录取的情况。基本思路是先按照学生的平均分(总分)进行排序,然后确定排名。然后从第一名开始陆续处理志愿学校,处理完第i名后才能处理第i+1名。要注意的是,当二人的名次相同但只有一个录取名额时,不需要考虑名额限制而要将二人同时录取。在解题中体现的就是:顺序查看第i人的K个志愿,当他的第j志愿学校名额充足时,正常录取;当第i人的第j个志愿学校已经没有名额时,如果该人的名次和他前面一人的名次相同,且他的第j个志愿和前一人的最终录取学校相同时,这个第i人可以被j志愿录取。

2、在处理完所有人的录取流程后,还无法直接输出。题目要求以学校为主进行输出。此时,如果设置M维数组记录M个学校分别录取的学生的id,还需要按id排序,将要遍历很多次stu数组,很可能超时。 这时可以再进行一次排序,按照学校序号的大小和学生的id综合排序,得到学校相同的学生在一起,且按照学生id从小到大排列。这时就可以输出了,有些学校没有人录取,只输出一个空行,需要在按照stu数组遍历时多加注意(需遍历到所有M个学校而非仅仅stu里的N个学生)。

3、由上可知,可以利用排序算法进行分类(当正常分类复杂度很高时)。

A1080. Graduate Admission的更多相关文章

  1. PAT甲级——A1080 Graduate Admission

    It is said that in 2011, there are about 100 graduate schools ready to proceed over 40,000 applicati ...

  2. PAT_A1080#Graduate Admission

    Source: PAT A1080 Graduate Admission (30 分) Description: It is said that in 2011, there are about 10 ...

  3. 题目1005:Graduate Admission

    题目1005:Graduate Admission 时间限制:1 秒 内存限制:32 兆 特殊判题:否 题目描述: It is said that in 2011, there are about 1 ...

  4. 题目1005:Graduate Admission(录取算法)

    题目链接:http://ac.jobdu.com/problem.php?pid=1005 详解链接:https://github.com/zpfbuaa/JobduInCPlusPlus 参考代码: ...

  5. PAT 1080 Graduate Admission[排序][难]

    1080 Graduate Admission(30 分) It is said that in 2011, there are about 100 graduate schools ready to ...

  6. pat1080. Graduate Admission (30)

    1080. Graduate Admission (30) 时间限制 200 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue It ...

  7. pat 甲级 1080. Graduate Admission (30)

    1080. Graduate Admission (30) 时间限制 200 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue It ...

  8. PAT 甲级 1080 Graduate Admission (30 分) (简单,结构体排序模拟)

    1080 Graduate Admission (30 分)   It is said that in 2011, there are about 100 graduate schools ready ...

  9. PAT-1080 Graduate Admission (结构体排序)

    1080. Graduate Admission It is said that in 2013, there were about 100 graduate schools ready to pro ...

随机推荐

  1. 【javascript】详解javaScript的深拷贝

        前言: 最开始意识到深拷贝的重要性是在我使用redux的时候(react + redux), redux的机制要求在reducer中必须返回一个新的对象,而不能对原来的对象做改动,事实上,当时 ...

  2. 先埋锅-CF-Valid BFS?-差一点没交上

    #include<iostream> #include<stdio.h> #include<string.h> #include<algorithm> ...

  3. visual studio 2013的使用和单元测试

    Visual Studio 2013 是一个先进的开发解决方案,各种规模的团队通过它均可设计和创建引人注目的应用程序.Visual Studio 13在新功能包括C#和VB编译器和IDE支持完全基于. ...

  4. 【Beta阶段】第九次Scrum Meeting!(论坛已成功上线)

    每日任务内容: 本次会议为第九次Scrum Meeting会议~ 本次会议为团队项目第九次会议,在会议前大家取得了重大成果! 队员 昨日完成任务 明日要完成任务 刘乾 #179 完成1021的数据处理 ...

  5. UML图中类之间的关系:依赖,泛化,关联,聚合,组合,实现(转)

    UML图中类之间的关系:依赖,泛化,关联,聚合,组合,实现   类与类图 1) 类(Class)封装了数据和行为,是面向对象的重要组成部分,它是具有相同属性.操作.关系的对象集合的总称. 2) 在系统 ...

  6. 第三个sprint冲刺第一阶段

  7. 第三个spring冲刺第9天

    今天是第三阶段冲刺的最后第二天了,我们该实现的功能基本已经全部实现了,有填空的,选择题的,还有计时的,目前就是在查BUG,看看有哪些地方有BUG需要修改,以下截图是我们团队所做的功能截图: 首页: 填 ...

  8. Daily Scrum 12-25

    Meeting Minutes 针对设计师提出的问题完成了layout的微调: 讨论alpha测试反馈反映出的一些问题: 完成了代码的merge(与bing词典 1.5版本): Progress   ...

  9. html 空白汉字占位符&#12288;

    在爬取京东评论时,复制html内容,发现文本中有些空格的宽度没见过.后来用htmlParser解析html页面时,发现这些空格都被替换为 . 12288是Unicode编码,&#表示宋体,&a ...

  10. vue为app做h5页面,如何做到同域名对应不同版本的h5代码

    1.当我们在做混合开发的时候,app端可以有无数多个版本,一般情况h5页面只有一套代码.应该如何部署多套代码呢? 2.业务场景 当出现这种情况的时候,其实前端可以部署多套代码.比如: www.stat ...