题目https://pintia.cn/problem-sets/994805342720868352/problems/994805387268571136

题意:

模拟高考志愿录取。

考生根据总成绩和高考成绩排名。根据排名往下录取,每个人有k个志愿。

如果他填的学校名额没有满,那么就可以被录取。如果他填的学校名额满了,最后一名的排名和这个人是一样的话,就可以被录取。

思路:

直接模拟。

刚开始居然有一个数据超时了,把排序的cmp里面改成传引用居然就过了。

  1. //#include<bits/stdc++>
  2. #include<stdio.h>
  3. #include<iostream>
  4. #include<algorithm>
  5. #include<cstring>
  6. #include<stdlib.h>
  7. #include<queue>
  8. #include<map>
  9. #include<stack>
  10. #include<set>
  11.  
  12. #define LL long long
  13. #define ull unsigned long long
  14. #define inf 0x3f3f3f3f
  15.  
  16. using namespace std;
  17.  
  18. int n, m, k;
  19. const int maxn = 4e4 + ;
  20. struct student{
  21. int ge, gi;
  22. int id;
  23. int gfinal;
  24. vector<int>apply;
  25. }stu[maxn];
  26.  
  27. bool cmp(student &a, student &b)
  28. {
  29. if(a.gfinal == b.gfinal){
  30. return a.ge > b.ge;
  31. }
  32. else return a.gfinal > b.gfinal;
  33. }
  34.  
  35. struct school{
  36. int quota;
  37. vector<student>addmit;
  38. }sch[];
  39.  
  40. bool cmpans(student &a, student &b)
  41. {
  42. return a.id < b.id;
  43. }
  44.  
  45. int main()
  46. {
  47. scanf("%d%d%d", &n, &m, &k);
  48. for(int i = ; i < m; i++){
  49. scanf("%d", &sch[i].quota);
  50. }
  51. for(int i = ; i < n; i++){
  52. stu[i].id = i;
  53. scanf("%d%d%", &stu[i].ge, &stu[i].gi);
  54. stu[i].gfinal = (stu[i].ge + stu[i].gi) / ;
  55. for(int j = ; j < k; j++){
  56. int s;
  57. scanf("%d", &s);
  58. stu[i].apply.push_back(s);
  59. }
  60. }
  61. sort(stu, stu + n, cmp);
  62.  
  63. for(int i = ; i < n; i++){
  64. for(int j = ; j < k; j++){
  65. int s = stu[i].apply[j];
  66. if(sch[s].quota){
  67. sch[s].addmit.push_back(stu[i]);
  68. sch[s].quota--;
  69. break;
  70. }
  71. else{
  72. if(sch[s].addmit.size()){
  73. student lastone = sch[s].addmit.back();
  74. if(lastone.gfinal == stu[i].gfinal && lastone.ge == stu[i].ge){
  75. sch[s].addmit.push_back(stu[i]);
  76. break;
  77. }
  78. }
  79. }
  80. }
  81. }
  82.  
  83. for(int i = ; i < m; i++){
  84. if(sch[i].addmit.size()){
  85. sort(sch[i].addmit.begin(), sch[i].addmit.end(), cmpans);
  86. printf("%d", sch[i].addmit[].id);
  87. for(int j = ; j < sch[i].addmit.size(); j++){
  88. printf(" %d", sch[i].addmit[j].id);
  89. }
  90. }
  91. printf("\n");
  92. }
  93.  
  94. return ;
  95. }

PAT甲级1080 Graduate Admission【模拟】的更多相关文章

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

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

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

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

  3. PAT甲级——A1080 Graduate Admission

    It is said that in 2011, there are about 100 graduate schools ready to proceed over 40,000 applicati ...

  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[排序][难]

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

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

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

  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 1080. Graduate Admission

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

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

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

随机推荐

  1. CentOS 7 安装 Oracle 11.2.0.4

    一.安装环境 CentOS Linux release 7.2.1511 (Core) Oracle Database 11g Release 2 (11.2.0.4) 二.安装前准备 2.1 修改主 ...

  2. PowerShell 显示气球提示框 2

    https://www.itninja.com/blog/view/reboot-required-toast-notifications-for-windows-machines [void][Sy ...

  3. 使用 TRESTClient 与 TRESTRequest 作为 HTTP Client(转)

    使用 TRESTClient 与 TRESTRequest 作为 HTTP Client 转自:http://www.cnblogs.com/dennieschang/p/6966403.html   ...

  4. java mqtt

    代码: package cc.gongchang.mqtt; import java.net.URISyntaxException; import org.fusesource.hawtdispatc ...

  5. lua 源码分析之线程对象lua_State

    lua_State 中放的是 lua 虚拟机中的环境表.注册表.运行堆栈.虚拟机的上下文等数据. 从一个主线程(特指 lua 虚拟机中的线程,即 coroutine)中创建出来的新的 lua_Stat ...

  6. NoSuchMethodError: The getter 'inputs' was called on null.

    I get this message : You have hit a bug in build_runner Please file an issue with reproduction steps ...

  7. 深入理解linux系统下proc文件系统内容

    深入理解linux系统下proc文件系统内容 内容摘要:Linux系统上的/proc目录是一种文件系统,即proc文件系统. Linux系统上的/proc目录是一种文件系统,即proc文件系统.与其它 ...

  8. MySql基本查询、连接查询、子查询、正则表达查询解说

    林炳文Evankaka原创作品.转载请注明出处http://blog.csdn.net/evankaka 查询数据指从数据库中获取所须要的数据.查询数据是数据库操作中最经常使用,也是最重要的操作.用户 ...

  9. 转:图像处理、显示中的行宽(linesize)、步长(stride)、间距(pitch)

    在图像数据传输和显示的过程中有一个不常用的参数:间距. 间距的名称: 它有很多的别名,在使用d3d显示的时候,它叫pitch:在用ffmpeg解码的时候,它叫linesize: 在用ffmpeg转换格 ...

  10. Software Engineer Title Ladder

    http://changelog.ca/log/2013/08/09/software_engineer_title_ladder Within the software engineering pr ...