1080 Graduate Admission——PAT甲级真题
1080 Graduate Admission——PAT甲级练习题
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 81 4
题目大意 :
这道题主要是让你模拟研究生录取的过程,题目的要求主要有一下几个方面:
- 每个报考人员一共有三个成绩分别为:GE, GI, final,其中final = (GE + GI) / 2;
- 录取的时候按照成绩排名从上往下录取
- 成绩排名的方式为:按照final的大小由高到低排序,如果final的值相同按照GE的值由高到低排序,如果GE和final的值都相同则两人排名相同
- 每个报考者都有K个选择,并且录取按照每个人的报考志愿顺序进行录取,如果其报考学校没有招满他就可以被录取,如果当前报考学校招满了则按照顺序看下一个报考学校能否录取。
- 如果有两个人报考同一个学校,并且两个人的排名相同,则报考学校无论是否招满都要将两人录取
- 注意报考人员的编号未0~N - 1,报考学校的编号为0~M - 1
题目思路:
- 我们定义一个结构体负责存储每一个报考人员的id,GE,GI,final.同时定义一个map<int, node> mirror;负责建立每个人的学号和个人信息之间的对应关系,方便在排完序之后进行查找。
- 定义map<int, vector<int> > addmission;建立学校编号和个人编号之间的映射关系,按照题目排序要求进行排序,对排序后的数据进行遍历。同时遍历每一个报考学生的报考学校,如果其当前报考学校没有招满,则被录取。如果其报考学校已经招满,然后就查看其报考学校录取的最后一名的成绩和当前考生的成绩是否相同,如果过两人成绩相同则录取无论当前学校是否招满
- 因为题目要求按照学号大小从小到达输出,但是学号存入的时候是乱序的,所以要对学号排序。
代码:
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
struct node {
int Ge, Gi, Gfinal;
vector<int> addmit;
int id, rank;
bool friend operator<(node a, node b) {
if (a.Gfinal == b.Gfinal) return a.Ge > b.Ge;
return a.Gfinal > b.Gfinal;
}
};
bool vis[N];
// node persons[N];
int n, m, k; // n是报名人数, m是学校数,
vector<int> school;
int main() {
scanf("%d%d%d", &n, &m, &k);
memset(vis, 0, sizeof(vis));
for (int i = 0; i < m; i++) {
int x;
scanf("%d", &x);
school.push_back(x);
}
vector<node> persons(n);
map<int, vector<int> > addmission;
map<int, node> mirror; //建立id和个人信息之间的映射关系
for (int i = 0; i < n; i++) {
int ge, gi, choices;
scanf("%d%d", &ge, &gi);
persons[i].id = i;
persons[i].Ge = ge, persons[i].Gi = gi,
persons[i].Gfinal = (ge + gi) / 2;
for (int j = 0; j < k; j++) {
scanf("%d", &choices);
persons[i].addmit.push_back(choices);
}
mirror[persons[i].id] = persons[i];
}
sort(persons.begin(), persons.end());
for (int i = 0; i < n; i++) {
auto tmp = persons[i].addmit;
if (vis[persons[i].id]) continue;
for (int j = 0; j < tmp.size(); j++) {
if (school[tmp[j]] != 0) {
school[tmp[j]]--;
vis[persons[i].id] = true;
addmission[tmp[j]].push_back(persons[i].id);
break;
}
//如果报考学校招满,则在报考学校中查找有没有和自己排名相同的人
else if (school[tmp[j]] <= 0) {
//此处可以优化,没有必要一个一个和目标院校的所有人比较排名,直接比较自己和最后一名的成绩即可
int len = addmission[tmp[j]].size();
int ite = addmission[tmp[j]][len - 1];
if (persons[i].Gfinal == mirror[ite].Gfinal &&
persons[i].Ge == mirror[ite].Ge) {
addmission[tmp[j]].push_back(persons[i].id);
vis[persons[i].id] = true;
break;
}
}
}
}
for (int i = 0; i < m; i++) {
if (addmission[i].empty())
cout << endl;
else {
sort(addmission[i].begin(), addmission[i].end());
int len = addmission[i].size();
for (int j = 0; j < len; j++) {
printf("%d", addmission[i][j]);
if (j != len - 1)
printf(" ");
else
printf("\n");
}
}
}
return 0;
}
1080 Graduate Admission——PAT甲级真题的更多相关文章
- PAT 甲级真题题解(63-120)
2019/4/3 1063 Set Similarity n个序列分别先放进集合里去重.在询问的时候,遍历A集合中每个数,判断下该数在B集合中是否存在,统计存在个数(分子),分母就是两个集合大小减去分 ...
- PAT 甲级真题题解(1-62)
准备每天刷两题PAT真题.(一句话题解) 1001 A+B Format 模拟输出,注意格式 #include <cstdio> #include <cstring> #in ...
- PAT甲级真题及训练集
正好这个"水水"的C4来了 先把甲级刷完吧.(开玩笑-2017.3.26) 这是一套"伪题解". wacao 刚才登出账号测试一下代码链接,原来是看不到..有空 ...
- PAT 甲级真题
1019. General Palindromic Number 题意:求数N在b进制下其序列是否为回文串,并输出其在b进制下的表示. 思路:模拟N在2进制下的表示求法,“除b倒取余”,之后判断是否回 ...
- PAT甲级真题 A1025 PAT Ranking
题目概述:Programming Ability Test (PAT) is organized by the College of Computer Science and Technology o ...
- Count PAT's (25) PAT甲级真题
题目分析: 由于本题字符串长度有10^5所以直接暴力是不可取的,猜测最后的算法应该是先预处理一下再走一层循环就能得到答案,所以本题的关键就在于这个预处理的过程,由于本题字符串匹配的内容的固定的PAT, ...
- 1018 Public Bike Management (30分) PAT甲级真题 dijkstra + dfs
前言: 本题是我在浏览了柳神的代码后,记下的一次半转载式笔记,不经感叹柳神的强大orz,这里给出柳神的题解地址:https://blog.csdn.net/liuchuo/article/detail ...
- 1022 Digital Library——PAT甲级真题
1022 Digital Library A Digital Library contains millions of books, stored according to their titles, ...
- PAT甲级真题打卡:1001.A+B Format
题目: Calculate a + b and output the sum in standard format -- that is, the digits must be separated i ...
随机推荐
- jqXHR.fail()回调方法及其参数详细说明
jqXHR.fail()是一个可供选择的 error 回调选项的构造函数,.fail()方法取代了的过时的.error()方法.从 jQuery 1.5 开始,$.ajax()返回的jqXHR对象 实 ...
- Java创建线程四种方式
1.继承Thread类 public class MyThread extends Thread { public MyThread() { } public void run() { for(int ...
- A - 最长回文(马拉车算法//manacher)
给出一个只由小写英文字符a,b,c...y,z组成的字符串S,求S中最长回文串的长度.回文就是正反读都是一样的字符串,如aba, abba等 Input输入有多组case,不超过120组,每组输入为一 ...
- java的静态代码块和类变量的隐式覆盖
静态代码块特点:随着类的加载执行一次,且仅会执行一次 作用:初始化类中的static修饰的变量(static修饰的变量称为类变量.类变量和静态代码块差不多,类变量仅会被初始化一次) 一.静态代码块写法 ...
- Codeforces Round #652 (Div. 2) C. RationalLee 贪心
题意: t组输入,你有n个数,还有k个朋友,每一个朋友需要wi个数.意思就是你要给第i个朋友分配wi个数,输入保证w1+w2+...+wk=n 一个朋友的兴奋值是你分配给他的数中最大值加上最小值的和( ...
- 【luogu AT3957】[AGC023F] 01 on Tree
01 on Tree 题目链接:luogu AT3957 题目大意 有一棵根为 \(1\) 的树,每个节点有个值 \(0\) 或 \(1\). 然后每次你可以把一个没有父亲的点删除,然后把值放进一个数 ...
- 部署开源IP管理工具phpIPAM
一.安装环境程序: yum install httpd mariadb-server php php-cli php-gd php-common php-ldap php-pdo php-pear p ...
- OpenStack Train版-3.安装glance镜像服务
安装glance镜像服务 创建数据库并授权 mysql -u root create database glance; GRANT ALL PRIVILEGES ON glance.* TO 'gla ...
- Python-collections模块之defaultdict
defaultdict defaultdict 是 dict 类型的子类,正如其名,初始化时,可以给key指定默认值,什么意思呢?直接看代码.如果是普通的dict对象,访问一个不存在的key时,会报错 ...
- Gym - 101981D Country Meow(模拟退火)题解
题意: 给\(n\)个三维点,问最小覆盖球的半径. 思路: 模拟退火. 代码: #include<set> #include<map> #include<cmath> ...