Source:

PAT A1080 Graduate Admission (30 分)

Description:

It is said that in 2011, there are 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 (. 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 (≤), the total number of applicants; M (≤), the total number of graduate schools; and K (≤), 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 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:

  1. 11 6 3
  2. 2 1 2 2 2 3
  3. 100 100 0 1 2
  4. 60 60 2 3 5
  5. 100 90 0 3 4
  6. 90 100 1 2 0
  7. 90 90 5 1 3
  8. 80 90 1 0 2
  9. 80 80 0 1 2
  10. 80 80 0 1 2
  11. 80 70 1 3 2
  12. 70 80 1 2 3
  13. 100 100 0 2 4

Sample Output:

  1. 0 10
  2. 3
  3. 5 6 7
  4. 2 8
  5. 1 4

Keys:

  • 模拟题

Attention:

  • 利用结构体排序,需要注意id与新排名位序的映射,PAT的测试不太严格,可以参考牛客网最后一个测例

Code:

  1. /*
  2. Data: 2019-07-14 18:26:36
  3. Problem: PAT_A1080#Graduate Admission
  4. AC: 39:42
  5.  
  6. 题目大意:
  7. 初试Ge,复试Gi,总分(Ge+Gi)/2
  8. 按照总分,初试,依次排名;
  9. K个志愿,按照学校招生名额依次录取
  10. 相同排名且相同志愿的考生,无论招生名额是否已满,都要录取
  11. 输入:
  12. 第一行给出,考生数N<=4e4,学校数M<=1e2,志愿数K<=5
  13. 接下来一行,各学校的招生名额(0~m-1)
  14. 接下来N行,Ge,Gi,K个志愿
  15. 输出:
  16. 各学校的录取结果,考生号递增(0~n-1)
  17. 未招生则打印空行
  18.  
  19. 基本思路:
  20. 静态存储考生信息,用考生编号替代数据项排名
  21. 创建学校录取信息的列表,按照排名依次录取
  22. */
  23.  
  24. #include<cstdio>
  25. #include<vector>
  26. #include<algorithm>
  27. using namespace std;
  28. const int N=1e5,M=,K=;
  29. struct node
  30. {
  31. int ge,gi,g;
  32. int se[K];
  33. }info[N];
  34. int quota[M],link[N];
  35. vector<int> sch[M];
  36.  
  37. bool cmp(const int &a, const int &b)
  38. {
  39. if(info[a].g != info[b].g)
  40. return info[a].g > info[b].g;
  41. else
  42. return info[a].ge > info[b].ge;
  43. }
  44.  
  45. int main()
  46. {
  47. #ifdef ONLINE_JUDGE
  48. #else
  49. freopen("Test.txt", "r", stdin);
  50. #endif
  51.  
  52. int n,m,k;
  53. scanf("%d%d%d", &n,&m,&k);
  54. for(int i=; i<m; i++)
  55. scanf("%d", &quota[i]);
  56. for(int i=; i<n; i++)
  57. {
  58. link[i]=i;
  59. scanf("%d%d", &info[i].ge,&info[i].gi);
  60. for(int j=; j<k; j++)
  61. scanf("%d", &info[i].se[j]);
  62. info[i].g = info[i].ge + info[i].gi;
  63. }
  64. sort(link,link+n,cmp);
  65. for(int i=; i<n; i++)
  66. {
  67. int id = link[i];
  68. for(int j=; j<k; j++)
  69. {
  70. int cho = info[id].se[j];
  71. int len = sch[cho].size();
  72. if(len < quota[cho]){
  73. sch[cho].push_back(id);
  74. break;
  75. }
  76. else{
  77. int stu = sch[cho][len-];
  78. if(info[stu].g==info[id].g && info[stu].ge==info[id].ge){
  79. sch[cho].push_back(id);
  80. break;
  81. }
  82. }
  83. }
  84. }
  85. for(int i=; i<m; i++)
  86. {
  87. sort(sch[i].begin(),sch[i].end());
  88. for(int j=; j<sch[i].size(); j++)
  89. printf("%d%c", sch[i][j],j==sch[i].size()-?'\n':' ');
  90. if(sch[i].size() == )
  91. printf("\n");
  92. }
  93.  
  94. return ;
  95. }

结构体排序:

  1. #include<cstdio>
  2. #include<vector>
  3. #include<algorithm>
  4. using namespace std;
  5. const int STU=5e4,SCH=,SLT=;
  6. struct node
  7. {
  8. int id,gi,ge;
  9. int select[SLT];
  10. }stu[STU];
  11. int quo[SCH];
  12. vector<int> adm[SCH];
  13.  
  14. bool cmp(const node &a, const node &b)
  15. {
  16. if(a.gi+a.ge != b.gi+b.ge)
  17. return a.gi+a.ge > b.gi+b.ge;
  18. else
  19. return a.ge > b.ge;
  20. }
  21.  
  22. bool cmp2(const int &a, const int &b)
  23. {
  24. return stu[a].id < stu[b].id;
  25. }
  26.  
  27. int main()
  28. {
  29. #ifdef ONLINE_JUDGE
  30. #else
  31. freopen("Test.txt", "r", stdin);
  32. #endif // ONLINE_JUDGE
  33.  
  34. int n,m,k;
  35. scanf("%d%d%d", &n,&m,&k);
  36. for(int i=; i<m; i++)
  37. scanf("%d", &quo[i]);
  38. for(int i=; i<n; i++)
  39. {
  40. scanf("%d%d", &stu[i].ge,&stu[i].gi);
  41. stu[i].id = i;
  42. for(int j=; j<k; j++)
  43. scanf("%d", &stu[i].select[j]);
  44. }
  45. sort(stu,stu+n,cmp);
  46. for(int i=; i<n; i++)
  47. {
  48. for(int j=; j<k; j++)
  49. {
  50. int sch=stu[i].select[j];
  51. if(adm[sch].size() < quo[sch])
  52. {
  53. adm[sch].push_back(i);
  54. break;
  55. }
  56. else
  57. {
  58. int num = adm[sch].size();
  59. int last = adm[sch][num-];
  60. if(stu[last].gi==stu[i].gi && stu[last].ge==stu[i].ge)
  61. {
  62. adm[sch].push_back(i);
  63. break;
  64. }
  65. }
  66. }
  67. }
  68. for(int i=; i<m; i++)
  69. {
  70. sort(adm[i].begin(),adm[i].end(),cmp2);
  71. for(int j=; j<adm[i].size(); j++)
  72. printf("%d%c", stu[adm[i][j]].id,j==adm[i].size()-?'\n':' ');
  73. if(adm[i].size()==)
  74. printf("\n");
  75. }
  76.  
  77. return ;
  78. }

PAT_A1080#Graduate Admission的更多相关文章

  1. 题目1005:Graduate Admission

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

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

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

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

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

  4. pat1080. Graduate Admission (30)

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

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

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

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

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

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

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

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

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

  9. 1080. Graduate Admission (30)

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

随机推荐

  1. 96、搬家到csdn

    大家好: 今天开始会将所有的博客搬家到CSDN,以后请参考CSDN上的博客:http://blog.csdn.net/u012416045 谢谢 维真

  2. 业务基类对象BaseBLL

    using System; using System.Collections; using System.Data; using System.Text; using System.Collectio ...

  3. %matplotlib inline 被注释掉后,pycharm不能生成图

    目录 问题描述 解决方案 @ 问题描述 在 jupyter 编译器中 程序的开头,有这么一行 %matplotlib inline import numpy as np import matplotl ...

  4. Eclipes更改字体颜色

    有图有真像 更改字体大小

  5. java 并发——synchronized

    java 并发--synchronized 介绍 在平常我们开发的过程中可能会遇到线程安全性的问题,为了保证线程之间操作数据的正确性,我们第一想到的可能就是使用 synchronized 并且 syn ...

  6. 如何将英文版的Firefox添加中文版语言包

    http://ftp.mozilla.org/pub/firefox/releases/ xpi中下载zh_CN.xpi 文件 , 把文件拖拽进火狐浏览器 在地址栏输入”about:config”,回 ...

  7. VC2008中如何为MFC应用程序添加和删除消息响应函数

    最近重温<MFC Windows应用程序设计>第二版这本书,里面的代码全部是使用VC6.0写的,我Win7下安装的是VS2008开发环境. VC2008下添加和删除常见的消息响应函数有两种 ...

  8. fixture实战---通过fixure,解决方法依赖逻辑

    import pytest@pytest.fixture()def login(): print('输入用户名密码登陆') def test_cart(login): print('用例1,登陆后执行 ...

  9. BUUCTF 派大星的烦恼

    这道题做的累死了,题目关键在于思路,这里将做题的完整思路记下来.题目给了一张bmp,用010打开可以看出题目关键就在于这一段D和“,保存出来 "DD"DD""& ...

  10. react使用总结

    1.拿到页面首先需要设计好,每个组件该怎么实现,划分好组件可以减少重复代码,有的时候需要和后端确认才能形成正确的划分 2.页面上的需要展示的数据都是由后端数据而来,所以任何增删改查的数据都要从后端重新 ...