1080 Graduate Admission (30 分)(排序)【回顾】

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

生词

英文 解释
Graduate Admission 研究生入学
automate 使自动化
quota 限额

分析:

1.设立stu结构体,存储学生的id(防止排序后id打乱了顺序),GE和GI的成绩,总评成绩,排名,志愿学校的列表数组。
2.设立sch结构体,存储school[i]招生的名额限制maxNum,现在已经招收了的学生个数nowNum,招收的学生的id列表stuID,以及当前已经招收了的学生的排名的最后一名lastRank。
3.把学生按照成绩进行排序,并赋值排名。如果GE一样且Grade一样,他们的名次就是一样的。
4.从第一个学生开始,根据他的志愿,来尝试被学校录取。如果当前学校名额未满。那么就录取进去,并且让学校的nowNum加1.并且更新lastRank为这个学生的rank。如果当前学校的lastRank等于自己的rank,那么不管名额满不满都录取。而且记得把学生的id添加到学校的stuID列表中。

5.输出的时候因为id顺序是乱的,要先从小到大排序,然后输出。每个学校占一行、

原文链接:https://blog.csdn.net/liuchuo/article/details/52493707

题解

这里用的存放 学校录取的学生列表 结构些许复杂,拆开看一下:

sch[0]					sch[1] 	0:stu.id=0				0:stu.id=3 	1:stu.id=10	  sch[2]					sch[4] 	0:stu.id=5				null 	1:stu.id=6 	2:stu.id=7 

上面是根据学生id排序后的sch数组,他的每一个元素是一个vector<peo>,下面举例说明一下如果两个学生的fin与ge成绩都相同是如何比较的:

stu[i].fin==sch[schid][lastindex].fin && stu[i].ge==sch[schid][lastindex].ge

1.先定位到sch[schid],然后它是一个vector<peo>向量嘛;

2.接下来定位到他的最后一名学生那个结构体,比如sch[0][1],他就是10号学生;

3.之后找到他的fin成绩,与当前学生stu[i].fin进行比较;

4.同理,ge成绩也是这样找的。

#include <bits/stdc++.h>  using namespace std; struct peo {     int id,ge,gi,fin;     vector<int> choice; }; bool cmp(peo a,peo b){     if(a.fin!=b.fin) return a.fin>b.fin;     return a.ge>b.ge; } bool cmp1(peo a,peo b){     return a.id<b.id; } int main() { #ifdef ONLINE_JUDGE #else     freopen("1.txt", "r", stdin); #endif     int n,m,k,quota[110],cnt[110]={0};     cin>>n>>m>>k;     vector<peo> stu(n),sch[110];     for(int i=0;i<m;i++){         cin>>quota[i];     }     for(int i=0;i<n;i++){         cin>>stu[i].ge>>stu[i].gi;         stu[i].id=i;         stu[i].fin=stu[i].ge+stu[i].gi;         stu[i].choice.resize(k);         for(int j=0;j<k;j++){             cin>>stu[i].choice[j];         }     }     sort(stu.begin(),stu.end(),cmp);     for(int i=0;i<n;i++){         for(int j=0;j<k;j++){             int schid=stu[i].choice[j];             int lastindex=cnt[schid]-1;             if(cnt[schid]<quota[schid]||stu[i].fin==sch[schid][lastindex].fin && stu[i].ge==sch[schid][lastindex].ge){                 sch[schid].push_back(stu[i]);                 cnt[schid]++;                 break;             }         }     }     for(int i=0;i<m;i++){         sort(sch[i].begin(),sch[i].end(),cmp1);         for(int j=0;j<cnt[i];j++){             if(j!=0) cout<<" ";             cout<<sch[i][j].id;         }         cout<<endl;     }     return 0; } 

推荐这些技术文章:

PAT_A 1080 Graduate Admission

PAT_A 1080 Graduate Admission
分析
题目模拟一个志愿填报系统。按照总分数(入学考试分数G1与面试的分数G2)从高到低模拟填志愿。

若两学生的总分(tot)、入学考试分数(G1)分别都相同,则认为排名相同。
排名相同的学生填报同一所学校时可以超出学校计划配额(quota)。
一位学生只能被一所学校录取。
录取的表示这里采用了一个很大的bool数组,采用链表或其他结构...

1080 Graduate Admission (30分) 简单模拟+STL(erase操作超时)

题目
https://pintia.cn/problem-sets/994805342720868352/problems/994805387268571136
题意
模拟高校投档流程
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...

30天英语口语背诵材料:PASSAGE 2: Learning: a Lifelong Career

  As food is to the body, so is learning to the mind. Our bodies grow and muscles develop with the intake of food. Likewise, we should keep learning day by day to maintain our mental power ...

王道机试指南题解(C/C++版)

第 2 章 经典入门
一 排序
例 2.1 排序

代码 2.1
冒泡排序(时间复杂度 \(O(n^2)\))
#include <iostream>
using std::cin; using std::cout; using std::endl;

#include <vector>
using std::vector;

#include <algorith...

L1-020 帅到没朋友 (20 point(s))

最开始用了 set 但最后一个测试点超时了,想了想这遍历是顺序的,不需要考虑排序,所以用了 unordered_set 就把最后一个测试点给解决了。
而想了想既然 unordered_set 都可以,那么类似的向量 vector 也应该是可以的,所以就改成向量试了试。但结果发现却超时了。
故查了查这两个容器的比较。向量是 vector 线性表,而 unordered_set 是hash容器。...

Vue 样式绑定 && 条件渲染

 

1 <!DOCTYPE html>
2 <html>
3 <head>
4 <meta charset="UTF-8" />
5 <title>Vue 样式绑定</title>
6 <style>
7 ...

Educational Codeforces Round 129 (Rated for Div. 2)

Educational Codeforces Round 129 (Rated for Div. 2)
https://codeforces.com/contest/1681
A. Game with Cards
直接比较最大的谁更大,谁就是赢家。
相等情况下,先手胜
#include <bits/stdc++.h>

using namespace std;

void solve...

黑马程序员-传智健康项目(第八章)

传智健康项目

黑马程序员-传智健康项目(第一章)
黑马程序员-传智健康项目(第二章)
黑马程序员-传智健康项目(第三章)
黑马程序员-传智健康项目(第四章)
黑马程序员-传智健康项目(第五章)
黑马程序员-传智健康项目(第六章)
黑马程序员-传智健康项目(第七章)
黑马程序员-传智健康项目(第八章)
黑马程序员-传智健康项目(第九章)
黑马程序员-传智健康项目(第十章)
黑马程序员-传智健康项...

十款代码表白特效,一个比一个浪漫!

原创不易,本文禁止抄袭、转载,侵权必究!

 
提到程序员,就会出现许多关键词,诸如“直男,宅,不懂浪漫,枯燥,憨厚老实,有逻辑,人傻钱多…………”
 
说程序猿是直男,不可否认,大多数程序猿都挺直,因为我们没有那么多弯弯绕绕,有心思兜圈子,不如回去写几行代码………
 
雷军曾经说“我喜欢写代码,代码的世界很简单”

 
程序猿的大多数时间都是面对电脑,...

Educational Codeforces Round 129 (Rated for Div. 2) A - D 题解

传送门
A. Game with Cards
看最大的在谁那,谁就赢
如果最大的都一样,则先手赢
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#i...

文章标题:1080 Graduate Admission (30 分)(排序)【回顾】
文章链接:https://www.dianjilingqu.com/1570.html
本文章来源于网络,版权归原作者所有,如果本站文章侵犯了您的权益,请联系我们删除,联系邮箱:saisai#email.cn,感谢支持理解。
THE END
< <上一篇
下一篇>>