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 G~E~, and the interview grade G~I~. The final grade of an applicant is (G~E~ + G~I~) / 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 G~E~. 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 G~E~ and G~I~, 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 <stdio.h>
#include <stdlib.h>
///按最终成绩排名,如果最终成绩相同,就按考试成绩,如果还相同就排名相同
///每个人可能有k个选择,如果学校人满了,就不行,如果排名相同都申请一个学校,即使人满了也收下所有人。
typedef struct app app;
struct app {
int id,ge,gi,fin,where;
int choice[];///志愿
}a[];
int n,m,k;
int need[],have[][],havenum[];///need是学校招收人数 have是学校已经招收的人 havenum是学校已经招收的人数
int cmp(const void *a,const void *b) {
app *aa = (app *)a,*bb = (app *)b;
if(aa -> fin == bb -> fin)return bb -> ge - aa -> ge;
return bb -> fin - aa -> fin;
}
int cmp1(const void *a,const void *b) {
return *(int *)a - *(int *)b;
}
int main() {
scanf("%d%d%d",&n,&m,&k);
for(int i = ;i < m;i ++) {
scanf("%d",&need[i]);
}
for(int i = ;i < n;i ++) {
a[i].id = i;
scanf("%d%d",&a[i].ge,&a[i].gi);
a[i].fin = (a[i].ge + a[i].gi) / ;///求最终成绩
for(int j = ;j < k;j ++) {
scanf("%d",&a[i].choice[j]);
}
}
qsort(a,n,sizeof(app),cmp);///进行排名
for(int i = ;i < n;i ++) {
int *p = a[i].choice;
for(int j = ;j < k;j ++) {
///如果学校还有空 或者 上一个人和自己排名相同且已经进入该学校 那么就可以进入
if(need[p[j]] - havenum[p[j]] > || i && a[i - ].fin == a[i].fin && a[i - ].ge == a[i].ge && a[i - ].where == p[j]) {
have[p[j]][havenum[p[j]] ++] = a[i].id;
a[i].where = p[j];
break;
}
}
}
for(int i = ;i < m;i ++) {
qsort(have[i],havenum[i],sizeof(int),cmp1);
for(int j = ;j < havenum[i];j ++) {
if(j)putchar(' ');
printf("%d",have[i][j]);
}
putchar('\n');
}
}

1080 Graduate Admission (30)(30 分)的更多相关文章

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

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

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

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

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

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

  4. 1080 Graduate Admission——PAT甲级真题

    1080 Graduate Admission--PAT甲级练习题 It is said that in 2013, there were about 100 graduate schools rea ...

  5. 【PAT甲级】1080 Graduate Admission (30 分)

    题意: 输入三个正整数N,M,K(N<=40000,M<=100,K<=5)分别表示学生人数,可供报考学校总数,学生可填志愿总数.接着输入一行M个正整数表示从0到M-1每所学校招生人 ...

  6. 1080. Graduate Admission (30)

    时间限制 200 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue It is said that in 2013, there w ...

  7. PAT 1080. Graduate Admission (30)

    It is said that in 2013, there were about 100 graduate schools ready to proceed over 40,000 applicat ...

  8. PAT (Advanced Level) 1080. Graduate Admission (30)

    简单题. #include<cstdio> #include<cstring> #include<cmath> #include<vector> #in ...

  9. 1080. Graduate Admission (30)-排序

    先对学生们进行排序,并且求出对应排名. 对于每一个学生,按照志愿的顺序: 1.如果学校名额没满,那么便被该学校录取,并且另vis[s][app[i].ranks]=1,表示学校s录取了该排名位置的学生 ...

随机推荐

  1. dede列表页调用文章,其实是所有页面都可以调用,第一次应用sql标签

    {dede:sql sql="SELECT aid,typeid,body,userip FROM `#@__addonarticle` where aid='6' or aid='7' o ...

  2. jquery中this和$(this)使用的地方

    插件中this代表$('元素')选择器 on()函数中this代表单个元素,$(this)代表单个选择器 反正有时代表整体,有时代表单个,代表单个时可以用$(this)来把他变成jquery对象

  3. unslider点导航不显示错误

    原因是,unslider插件只添加了dots文件并没有设置样式 解决办法 .banner { position: relative; width: 100%; overflow: auto; font ...

  4. 如何利用Require.Js管理多页面站点文件(译)

    英文版地址 最近使用 Require.Js 的时候我发现它确实是一个改善代码管理的一个好方法.我以前发表Backbone类的文章时曾提到过 Require,但此前,我从未在传统的多页面网站内使用到 R ...

  5. python创建迅雷批量任务

    其实不是真的创建了批量任务,而是用python创建一个文本文件,每行一个要下载的链接,然后打开迅雷,复制文本文件的内容,迅雷监测到剪切板变化,弹出下载全部链接的对话框~~ 实际情况是这样的,因为用py ...

  6. smokeping插件使用及说明

    smokeping七大组件:general(普通设置) .alerts(警报设置).Datebase(数据库参数).presentation(网络自定义).slaves(从smokeping定义).t ...

  7. WampServer无法直接打开myprojects的解决方法

    https://jingyan.baidu.com/article/7e4409533ace042fc1e2ef40.html

  8. ASP.NET动态网站制作(2)--css(1)

    前言:这节课主要讲关于css的相关内容. 重点:1.css(Cascading Style Sheet)叠层样式表,做网页的外观,是用来控制网页样式并允许将样式信息与网页内容分离的一种标记性语言. 2 ...

  9. 数据结构:最小生成树--Kruskal算法

    Kruskal算法 Kruskal算法 求解最小生成树的还有一种常见算法是Kruskal算法.它比Prim算法更直观.从直观上看,Kruskal算法的做法是:每次都从剩余边中选取权值最小的,当然,这条 ...

  10. 九度OJ 1165:字符串匹配 (模式匹配)

    时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:3219 解决:1149 题目描述: 读入数据string[ ],然后读入一个短字符串.要求查找string[ ]中和短字符串的所有匹配,输出 ...