1080. Graduate Admission

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

题目大意:学生申请学校的问题,有n个学生,m所学校,每个学生最多填报的志愿数为k,给出这m所学校的名额数。每个学生有GE和GI两门成绩,平均成绩高的则排在前面;若相等,则GE高的排在前面;再相等则排名相同。对于排名相同的学生,即使名额不够了也会一并接受,接着给出每个学生填报的k个学校的序号。要求输出每个学校最终招到的学生的序号。



主要思路:1. 建立包含每个学生的结构体数组,每个结构体包括学生的序号id,两项成绩gi和ge,以及一个含有其报名学校的数组;以一个二维的vector容器存放每个学校招收的学生,另用一个数组存放每个学校当前剩余的名额;

2. 成绩好的先选。按照成绩排序结构体数组,然后从前到后让每个学生依次选择学校,如果当前志愿学校名额>0,则被录取,该学校的名额数-1;如果名额=0,则与该学校已录取的最后一个学生比较,如果两人两门成绩分别相同,则该生被录取,否则考虑下一个志愿。注意要对每一个学校录取的学生的序号排序后再输出。

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef struct info {
int id; //申请者序号(防止因排序打乱)
int ge, gi;
int school[5]; //申请者志愿
} applicant;
applicant a[40000];
int quota[100];
bool comp(applicant v, applicant w);
bool comp_id(applicant v, applicant w); int main(void) {
int n, m, k, i, j; cin >> n >> m >> k;
vector<vector<applicant> > vec(m);
for (i = 0; i < m; i++)
cin >> quota[i];
for (i = 0; i < n; i++) {
a[i].id = i;
cin >> a[i].ge >> a[i].gi;
for (j = 0; j < k; j++)
cin >> a[i].school[j];
}
sort(a, a + n, comp);
for (i = 0; i < n; i++) {
for (j = 0; j < k; j++) {
int id = a[i].school[j]; //成绩排行第i的申请者的第j个志愿的学校
if (quota[id] > 0) {
vec[id].push_back(a[i]);
quota[id]--;
break;
}
else if (quota[id] == 0) {
applicant t = vec[id].back(); //序号为id的学校录取的成绩最低的同学
if (a[i].ge == t.ge && a[i].gi == t.gi) { //成绩完全相同才说明排名相同
vec[id].push_back(a[i]);
break;
}
}
}
}
for (i = 0; i < m; i++) {
if (vec[i].size() == 0) {
cout << "\n";
continue;
}
sort(vec[i].begin(), vec[i].end(), comp_id); //对容器中的学生序号进行排序
cout << vec[i][0].id;
for (j = 1; j < vec[i].size(); j++)
cout << " " << vec[i][j].id;
cout << endl;
} return 0;
}
//按成绩排序
bool comp(applicant v, applicant w) {
if (v.ge + v.gi == w.ge + w.gi)
return v.ge > w.ge;
return (v.ge + v.gi) > (w.ge + w.gi);
}
//按序号排序
bool comp_id(applicant v, applicant w) {
return v.id < w.id;
}

PAT-1080 Graduate Admission (结构体排序)的更多相关文章

  1. 题目1005:Graduate Admission(结构体排序)

    问题来源 http://ac.jobdu.com/problem.php?pid=1005 问题描述 这道题理解题意有些麻烦,多看几遍先理解题意再说.每个学生有自己的三个成绩,一个编号,以及一个志愿列 ...

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

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

  3. PAT 1080. Graduate Admission (30)

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

  4. PAT 1080. Graduate Admission

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

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

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

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

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

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

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

  8. PAT 乙级 1085. PAT单位排行 (25) 【结构体排序】

    题目链接 https://www.patest.cn/contests/pat-b-practise/1085 思路 结构体排序 要注意几个点 它的加权总分 是 取其整数部分 也就是 要 向下取整 然 ...

  9. HDOJ 1009. Fat Mouse' Trade 贪心 结构体排序

    FatMouse' Trade Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

随机推荐

  1. Lambda表达式最佳实践

    简介 Lambda表达式java 8引入的函数式编程框架.之前的文章中我们也讲过Lambda表达式的基本用法. 本文将会在之前的文章基础上更加详细的讲解Lambda表达式在实际应用中的最佳实践经验. ...

  2. 微软开放 Build 2020 免费注册

    微软已经开放 Build 2020 线上开发者会议注册,https://mybuild.microsoft.com/.Build 2020 会议将于 5 月 19 日至 20 日召开,核心内容都是围绕 ...

  3. Pycharm中设置encoding

    在Pycharm专业版中,为了防止文件在别的机器上出现乱码,所以需要进行字符编码的设置. 首先在Pycharm中的View中将下图中的Toolbar打上勾. 接着,工具栏就会出现,选中settings ...

  4. tomcat项目迁移,无法访问,报“404”错误,原因分析

    首先,导出项目文件和MySQL数据库(项目文件直接tar&&cp:数据库直接mysqldump生成sql文件) 再,进行导入步骤,项目文件拷贝到webapps下,并赋予bin相关文件执 ...

  5. jQuery学习(三)

    事件 on方法可以将一个事件绑定在jQuery对象上,当你的操作触发了这些事件时,便会调用你所绑定的函数. 例如,给某个超链接绑定点击事件. <head> <meta http-eq ...

  6. js数组排序和打乱

    js数组根据不同的业务需求,会要求数组有序或者无序,记录一下流传较广,通用性较强的排序和乱序方法. 数组排序: arr.sort(function(a,b){//从小到大 return a-b;[re ...

  7. Makefile中的CFLAGS,LDFLAGS,LIBS

    CFLAGS:C编译器选项,而CXXFLAGS表示C++编译器的选项 1. CFLAGS参数 选项 说明 -c 用于把源码编译成.o对象文件,不进行链接过程 -o 用于连接生成可执行文件,在其后可以指 ...

  8. python(面向对象-类封装调用)

    一.面对对象思想 (1)大家肯定听过 Python 中”一切皆对象“的说法,但可能并不了解它的具体含义,只是在学习的时候听说 Python 是面向对象的编程语言,本节将向大家详细介绍 Python 面 ...

  9. System类&StringBuilder类

    System类 1.currentTimeMillis()方法 作用:获取当前系统时间的毫秒值[注意:从现在到1970年1月1日 00:00:00] 2.arraycopy(...)方法 作用:复制数 ...

  10. Coursera课程笔记----计算导论与C语言基础----Week 7

    C语言中的数据成分(Week7) 内存 把内存想象成长带,带子上有许多方格,每个方格有8位(8bit) 2^10 = 1024 1B = 8 b 1KB = 1024Byte MB.GB.TB.PB- ...