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 ...
随机推荐
- C#& Screen 类&(&多&屏&幕&开&发)
原文:C#& Screen 类&(&多&屏&幕&开&发) Screen 类 下面的代码示例演示如何使用 Screen 类的各种方法和属性. 该示 ...
- Python学习笔记(四)——文件永久存储
文件的永久存储 pickle模块的使用 pickle的实质就是将数据对象以二进制的形式存储 存储数据 pickle.dump(data,file) data表示想要存储的数据元素,file表示要将数据 ...
- SpringBoot防止重复请求,重复表单提交超级简单的注解实现
1. 注解接口 /** * @description 防止表单重复提交注解 */@Retention(RetentionPolicy.RUNTIME)@Target(ElementType.METHO ...
- soapui打开即报错------连接不上Internet
1.遇到的问题: 打开soapui即报错,如下: You're getting this message since your computer is offline and SoapUI can't ...
- Java 多线程 - 创建线程的方法 + Executors.newXXXThreadPool()缺点
java中创建线程的三种方法以及区别: https://www.cnblogs.com/3s540/p/7172146.html 通过Executor 的工具类,创建三种类型的普通线程池: https ...
- 【JZOJ4474】【luoguP4071】排列计数
description 求有多少种长度为 n 的序列 A,满足以下条件: (1)1 ~ n 这 n 个数在序列中各出现了一次 (2)若第 i 个数 A[i] 的值为 i,则称 i 是稳定的.序列恰好有 ...
- 校园商铺-2项目设计和框架搭建-9验证Service
1. 新建接口 main: com.csj2018.o2o.service/AreaService.java package com.csj2018.o2o.service; import java. ...
- Byte[]和Stream相互转换
C# Stream 和 byte[] 之间的转换 一. 二进制转换成图片 MemoryStream ms = new MemoryStream(bytes); ms.Position = 0; Ima ...
- Duilib中各个类的简单介绍
DirectUI意为直接在父窗口上绘图(Paint on parent dc directly).即子窗口不以窗口句柄的形式创建(windowless),只是逻辑上的窗口,绘制在父窗口之上.微软的“D ...
- duilib教程之duilib入门简明教程11.部分bug
一.WindowImplBase的bug 在第8个教程[2013 duilib入门简明教程 -- 完整的自绘标题栏(8)]中,可以发现窗口最大化之后有两个问题, 1.最大化按钮的样式还是没 ...