PAT甲级——A1080 Graduate Admission
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 GE, and the interview grade GI. 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 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 (≤), 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 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
#include <iostream>
#include <vector>
#include <algorithm>
//录取规则,排名靠前的人优先选择学校
using namespace std;
int N, M, K;
struct Node
{
int id, Ge, Gt, G, rank, choice[];
}node;
struct Sch
{
int quto;
vector<pair<int,int>>admin;//录取的学生id,rank
}sch;
vector<Sch>school;
vector<Node>applicant;
bool cmp(Node a, Node b)
{
if (a.G != b.G)
return a.G > b.G;
else
return a.Ge > b.Ge;
}
int main()
{
cin >> N >> M >> K;
for (int i = ; i < M; ++i)
{
cin >> sch.quto;
school.push_back(sch);
}
for (int i = ; i < N; ++i)
{
cin >> node.Ge >> node.Gt;
node.G = node.Ge + node.Gt;
node.id = i;
for (int j = ; j < K; ++j)
{
int t;
cin >> t;
node.choice[j] = t;//志愿学校
}
applicant.push_back(node);
}
sort(applicant.begin(), applicant.end(), cmp);
applicant[].rank = ;
for (int i = ; i < N; ++i)//排名
{
if (applicant[i].G == applicant[i - ].G && applicant[i].Ge == applicant[i - ].Ge)
applicant[i].rank = applicant[i - ].rank;
else
applicant[i].rank = i + ;
}
for (int i = ; i < N; ++i)//按学生选学校
{
for (int j = ; j < K; ++j)
{
int t = applicant[i].choice[j];
if (school[t].quto == && (school[t].admin.end() - )->second == applicant[i].rank)//排名相同可以超额
{
school[t].admin.push_back(make_pair(applicant[i].id, applicant[i].rank));//超额录取
break;
}
else if (school[t].quto == )
continue;//面试下一所学校,该学校满额
else
{
school[t].admin.push_back(make_pair(applicant[i].id, applicant[i].rank));//正常录取
school[t].quto--;//名额减少
break;
}
}
}
for (int i = ; i < M; ++i)
{
sort(school[i].admin.begin(), school[i].admin.end());
for (int j = ; j < school[i].admin.size(); ++j)
cout << school[i].admin[j].first << (j == school[i].admin.size() - ? "" : " ");
cout << endl;
}
return ;
}
PAT甲级——A1080 Graduate Admission的更多相关文章
- pat 甲级 1080. Graduate Admission (30)
1080. Graduate Admission (30) 时间限制 200 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue It ...
- PAT 甲级 1080 Graduate Admission (30 分) (简单,结构体排序模拟)
1080 Graduate Admission (30 分) It is said that in 2011, there are about 100 graduate schools ready ...
- PAT甲级1080 Graduate Admission【模拟】
题目:https://pintia.cn/problem-sets/994805342720868352/problems/994805387268571136 题意: 模拟高考志愿录取. 考生根据总 ...
- A1080. Graduate Admission
It is said that in 2013, there were about 100 graduate schools ready to proceed over 40,000 applicat ...
- PAT_A1080#Graduate Admission
Source: PAT A1080 Graduate Admission (30 分) Description: It is said that in 2011, there are about 10 ...
- 1080 Graduate Admission——PAT甲级真题
1080 Graduate Admission--PAT甲级练习题 It is said that in 2013, there were about 100 graduate schools rea ...
- PAT 1080 Graduate Admission[排序][难]
1080 Graduate Admission(30 分) It is said that in 2011, there are about 100 graduate schools ready to ...
- PAT甲级题解(慢慢刷中)
博主欢迎转载,但请给出本文链接,我尊重你,你尊重我,谢谢~http://www.cnblogs.com/chenxiwenruo/p/6102219.html特别不喜欢那些随便转载别人的原创文章又不给 ...
- 【转载】【PAT】PAT甲级题型分类整理
最短路径 Emergency (25)-PAT甲级真题(Dijkstra算法) Public Bike Management (30)-PAT甲级真题(Dijkstra + DFS) Travel P ...
随机推荐
- 【图论】tarjan
刚接触tarjan,tarjan其实更多是用来找强联通分量.我这里呢,是看qsc的视频学的.卿学姐讲的其实很清楚啦. 我这里只是做个整理. low[]:表示能到达这个点的最小编号.[树枝边].啊,其实 ...
- Flutter 打包报错 : Unknown FLUTTER_BUILD_MODE: xxx
概要 在集成flutter 工程之后,我们的工程在debug 和release 模式下都没什么问题,一切都很顺利.但是我们在打企业包的时候却出现了错误: Showing Recent Errors O ...
- boost相关函数
1.boost::scoped_ptr是一个比较简单的智能指针,它能保证在离开作用域之后它所管理对象能被自动释放 #include <iostream> #include <boos ...
- Linux 常用命令:开发调试篇
前言 Linux常用命令中有一些命令可以在开发或调试过程中起到很好的帮助作用,有些可以帮助了解或优化我们的程序,有些可以帮我们定位疑难问题.本文将简单介绍一下这些命令. 示例程序 我们用一个小程序,来 ...
- Oracle闪回查询恢复delete删除数据
Flashback query(闪回查询)原理 Oracle根据undo信息,利用undo数据,类似一致性读取方法,可以把表置于一个删除前的时间点(或SCN),从而将数据找回. Flashback q ...
- csps模拟83最大异或和简单的括号序列旅行计划题解
题面:https://www.cnblogs.com/Juve/articles/11733280.html 最大异或和: 简单博弈,小Q一定不会输,如果异或和为0,则平局,因为无论小Q如何拿,小T都 ...
- SQLite3与C++的结合应用
SQLite并没有一次性做到位,只有下载这些东西是不能放在vs2010中并马上使用的,下载下来的文件中有sqlite3.c/h/dll/def,还是不够用的.我们需要的sqlite3.lib文件并不在 ...
- (转)iframe 高度100%时,出现垂直滚动条
问题 需求是这样的,iframe在一个div中,并且iframe高度与div一样,所以设置了iframe高度是100%,结果div出现了滚动条,在排除了padding.margin的因素外,还是有滚动 ...
- 转: sizeof,总结
源地址:http://blog.csdn.net/freefalcon/article/details/54839 0. 前向声明 sizeof,一个其貌不扬的家伙,引无数菜鸟竟折腰,小虾我当初也没少 ...
- 第五篇:zTree节点的一些操作,权当备份
项目场景:将zTree的一个节点挪到某个已知的根节点下,因为树上的节点都是数据库查询出来的,所以不能直接用addNodes()这个方法(否则一刷新又恢复原样了),而是要把这个节点及其某些属性数据保存到 ...