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 8

1 4

题目大意

这道题主要是让你模拟研究生录取的过程,题目的要求主要有一下几个方面:

  1. 每个报考人员一共有三个成绩分别为:GE, GI, final,其中final = (GE + GI) / 2;
  2. 录取的时候按照成绩排名从上往下录取
  3. 成绩排名的方式为:按照final的大小由高到低排序,如果final的值相同按照GE的值由高到低排序,如果GE和final的值都相同则两人排名相同
  4. 每个报考者都有K个选择,并且录取按照每个人的报考志愿顺序进行录取,如果其报考学校没有招满他就可以被录取,如果当前报考学校招满了则按照顺序看下一个报考学校能否录取。
  5. 如果有两个人报考同一个学校,并且两个人的排名相同,则报考学校无论是否招满都要将两人录取
  6. 注意报考人员的编号未0~N - 1,报考学校的编号为0~M - 1

题目思路

  1. 我们定义一个结构体负责存储每一个报考人员的id,GE,GI,final.同时定义一个map<int, node> mirror;负责建立每个人的学号和个人信息之间的对应关系,方便在排完序之后进行查找。
  2. 定义map<int, vector<int> > addmission;建立学校编号和个人编号之间的映射关系,按照题目排序要求进行排序,对排序后的数据进行遍历。同时遍历每一个报考学生的报考学校,如果其当前报考学校没有招满,则被录取。如果其报考学校已经招满,然后就查看其报考学校录取的最后一名的成绩和当前考生的成绩是否相同,如果过两人成绩相同则录取无论当前学校是否招满
  3. 因为题目要求按照学号大小从小到达输出,但是学号存入的时候是乱序的,所以要对学号排序。

代码

  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. const int N = 1e5 + 10;
  4. struct node {
  5. int Ge, Gi, Gfinal;
  6. vector<int> addmit;
  7. int id, rank;
  8. bool friend operator<(node a, node b) {
  9. if (a.Gfinal == b.Gfinal) return a.Ge > b.Ge;
  10. return a.Gfinal > b.Gfinal;
  11. }
  12. };
  13. bool vis[N];
  14. // node persons[N];
  15. int n, m, k; // n是报名人数, m是学校数,
  16. vector<int> school;
  17. int main() {
  18. scanf("%d%d%d", &n, &m, &k);
  19. memset(vis, 0, sizeof(vis));
  20. for (int i = 0; i < m; i++) {
  21. int x;
  22. scanf("%d", &x);
  23. school.push_back(x);
  24. }
  25. vector<node> persons(n);
  26. map<int, vector<int> > addmission;
  27. map<int, node> mirror; //建立id和个人信息之间的映射关系
  28. for (int i = 0; i < n; i++) {
  29. int ge, gi, choices;
  30. scanf("%d%d", &ge, &gi);
  31. persons[i].id = i;
  32. persons[i].Ge = ge, persons[i].Gi = gi,
  33. persons[i].Gfinal = (ge + gi) / 2;
  34. for (int j = 0; j < k; j++) {
  35. scanf("%d", &choices);
  36. persons[i].addmit.push_back(choices);
  37. }
  38. mirror[persons[i].id] = persons[i];
  39. }
  40. sort(persons.begin(), persons.end());
  41. for (int i = 0; i < n; i++) {
  42. auto tmp = persons[i].addmit;
  43. if (vis[persons[i].id]) continue;
  44. for (int j = 0; j < tmp.size(); j++) {
  45. if (school[tmp[j]] != 0) {
  46. school[tmp[j]]--;
  47. vis[persons[i].id] = true;
  48. addmission[tmp[j]].push_back(persons[i].id);
  49. break;
  50. }
  51. //如果报考学校招满,则在报考学校中查找有没有和自己排名相同的人
  52. else if (school[tmp[j]] <= 0) {
  53. //此处可以优化,没有必要一个一个和目标院校的所有人比较排名,直接比较自己和最后一名的成绩即可
  54. int len = addmission[tmp[j]].size();
  55. int ite = addmission[tmp[j]][len - 1];
  56. if (persons[i].Gfinal == mirror[ite].Gfinal &&
  57. persons[i].Ge == mirror[ite].Ge) {
  58. addmission[tmp[j]].push_back(persons[i].id);
  59. vis[persons[i].id] = true;
  60. break;
  61. }
  62. }
  63. }
  64. }
  65. for (int i = 0; i < m; i++) {
  66. if (addmission[i].empty())
  67. cout << endl;
  68. else {
  69. sort(addmission[i].begin(), addmission[i].end());
  70. int len = addmission[i].size();
  71. for (int j = 0; j < len; j++) {
  72. printf("%d", addmission[i][j]);
  73. if (j != len - 1)
  74. printf(" ");
  75. else
  76. printf("\n");
  77. }
  78. }
  79. }
  80. return 0;
  81. }

1080 Graduate Admission——PAT甲级真题的更多相关文章

  1. PAT 甲级真题题解(63-120)

    2019/4/3 1063 Set Similarity n个序列分别先放进集合里去重.在询问的时候,遍历A集合中每个数,判断下该数在B集合中是否存在,统计存在个数(分子),分母就是两个集合大小减去分 ...

  2. PAT 甲级真题题解(1-62)

    准备每天刷两题PAT真题.(一句话题解) 1001 A+B Format  模拟输出,注意格式 #include <cstdio> #include <cstring> #in ...

  3. PAT甲级真题及训练集

    正好这个"水水"的C4来了 先把甲级刷完吧.(开玩笑-2017.3.26) 这是一套"伪题解". wacao 刚才登出账号测试一下代码链接,原来是看不到..有空 ...

  4. PAT 甲级真题

    1019. General Palindromic Number 题意:求数N在b进制下其序列是否为回文串,并输出其在b进制下的表示. 思路:模拟N在2进制下的表示求法,“除b倒取余”,之后判断是否回 ...

  5. PAT甲级真题 A1025 PAT Ranking

    题目概述:Programming Ability Test (PAT) is organized by the College of Computer Science and Technology o ...

  6. Count PAT's (25) PAT甲级真题

    题目分析: 由于本题字符串长度有10^5所以直接暴力是不可取的,猜测最后的算法应该是先预处理一下再走一层循环就能得到答案,所以本题的关键就在于这个预处理的过程,由于本题字符串匹配的内容的固定的PAT, ...

  7. 1018 Public Bike Management (30分) PAT甲级真题 dijkstra + dfs

    前言: 本题是我在浏览了柳神的代码后,记下的一次半转载式笔记,不经感叹柳神的强大orz,这里给出柳神的题解地址:https://blog.csdn.net/liuchuo/article/detail ...

  8. 1022 Digital Library——PAT甲级真题

    1022 Digital Library A Digital Library contains millions of books, stored according to their titles, ...

  9. PAT甲级真题打卡:1001.A+B Format

    题目: Calculate a + b and output the sum in standard format -- that is, the digits must be separated i ...

随机推荐

  1. redis学习教程三《发送订阅、事务、连接》

    redis学习教程三<发送订阅.事务.连接>  一:发送订阅      Redis发布订阅(pub/sub)是一种消息通信模式:发送者(pub)发送消息,订阅者(sub)接收消息.Redi ...

  2. Spring Cloud与Docker——微服务架构概述

    Spring Cloud与Docker--微服务架构概述 单体应用架构概述 微服务概述 微服务的特性 微服务架构的优点 微服务面临的挑战 微服务的设计原则 单体应用架构概述 传统的服务发布都是采用单体 ...

  3. UDP发送文件

    接收端 package com.zy.demo2; import java.io.File; import java.io.FileOutputStream; import java.net.Data ...

  4. 2019 Multi-University Training Contest 7 Kejin Player(期望)

    题意:给定在当前等级升级所需要的花费 每次升级可能会失败并且掉级 然后q次询问从l到r级花费的期望 思路:对于单次升级的期望 我们可以列出方程: 所以我们可以统计一下前缀和 每次询问O1回答 #inc ...

  5. gym101002K. Inversions (FFT)

    题意:给定一个仅含有AB的字母串 如果i有一个B j有一个A 且j>i 会对F(j-i)产生贡献 求出所有发Fi 题解:好像是很裸的FFT B的分布可以看作一个多项式 同理A也可以 然后把B的位 ...

  6. Educational Codeforces Round 88 (Rated for Div. 2) B. New Theatre Square(贪心)

    题目链接:https://codeforces.com/contest/1359/problem/B 题意 有一块 $n \times m$ 的地板和两种瓷砖: $1 \times 1$,每块花费为 ...

  7. Codeforces Round #646 (Div. 2) C. Game On Leaves (贪心,博弈)

    题意:给你一棵树,每次可以去掉叶节点的一条边,Ayush先开始,每回合轮流来,问谁可以第一个把\(x\)点去掉. 题解:首先如果\(x\)的入度为\(1\),就可以直接拿掉,还需要特判一下入度为\(0 ...

  8. JavaScript——六

    magin和padding的区别:https://www.cnblogs.com/zxnn/p/8186225.html magin:兄弟之间的 padding:父子关系 body和网页边框左右距离上 ...

  9. mysql+python+pymysql的一些细节问题

    报错 (1044, "Access denied for user 'erio'@'localhost' to database 'library'") 就是权限问题了,没什么好说 ...

  10. Http和Https之为什么Https更安全

    [除夕了,加油干.希望自己新的一年万事顺意,祝大家身体健康,心想事成!] 我们都知道 HTTPS 安全,可是为什么安全呢? 看小电影还是浏览正常网站,一定要检查是不是 HTTPS 的,因为Https相 ...