PAT 甲级 1080 Graduate Admission (30 分) (简单,结构体排序模拟)
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
题意:
有n个学生,m个学校,每个人可以填报的志愿为k个,每个人有两个成绩,笔试成绩GE,口试成绩GI,排名按照GE和GI的平均值计算,如果平均值相同,则按照GE排序,如果GE相同,则两学生排名相同
学校的录取规则为:按照成绩排序,再按照每一个 学生填报志愿的顺序,一次向下进行学校判断,如果学校没有收满学生,则录取,如果已经收满学生,但是最后一名收的学生和当前学生排名相同,即使名额超限,也会录取该学生
————————————————
版权声明:本文为CSDN博主「阿_波_」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/li1615882553/article/details/86380237
题解:
结构体排序,模拟即可
AC代码:
#include<bits/stdc++.h>
using namespace std;
int n,m,k;
struct node{
int id;
int rank;
int ge,gi;
vector<int>cho;
}a[];
int num[];
int ran[];
vector<int>sch[];
bool cmp(node x,node y){
if((x.ge+x.gi)==(y.ge+y.gi)){
return x.ge>y.ge;
}else{
return (x.ge+x.gi)>(y.ge+y.gi);
}
}
bool cmp2(int x,int y){
return x<y;
}
int main(){
cin>>n>>m>>k;
memset(ran,,sizeof(ran));
for(int i=;i<m;i++) cin>>num[i];
for(int i=;i<n;i++){
cin>>a[i].ge>>a[i].gi;
a[i].id=i;
for(int j=;j<=k;j++){
int x;
cin>>x;
a[i].cho.push_back(x);
}
}
sort(a,a+n,cmp);
for(int i=;i<n;i++){
if(i==) a[i].rank=;//计算排名
else{
if(a[i].ge==a[i-].ge && a[i].gi==a[i-].gi){
a[i].rank=a[i-].rank;
}else{
a[i].rank=a[i-].rank+;
}
}
for(int j=;j<k;j++){//开始分流志愿
int x=a[i].cho.at(j);
if(num[x]>||ran[x]==a[i].rank){//排名相同也可
sch[x].push_back(a[i].id);
num[x]--;
if(num[x]==) ran[x]=a[i].rank;
break;
}
}
}
for(int i=;i<m;i++){
sort(sch[i].begin(),sch[i].end(),cmp2);//学校内部排序
if(sch[i].size()!=){
for(int j=;j<sch[i].size();j++){
cout<<sch[i].at(j);
if(j!=sch[i].size()-) cout<<" ";
}
}
cout<<endl;
}
return ;
}
PAT 甲级 1080 Graduate Admission (30 分) (简单,结构体排序模拟)的更多相关文章
- pat 甲级 1080. Graduate Admission (30)
1080. Graduate Admission (30) 时间限制 200 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue It ...
- PAT 甲级 1016 Phone Bills (25 分) (结构体排序,模拟题,巧妙算时间,坑点太多,debug了好久)
1016 Phone Bills (25 分) A long-distance telephone company charges its customers by the following r ...
- 【PAT甲级】1080 Graduate Admission (30 分)
题意: 输入三个正整数N,M,K(N<=40000,M<=100,K<=5)分别表示学生人数,可供报考学校总数,学生可填志愿总数.接着输入一行M个正整数表示从0到M-1每所学校招生人 ...
- PAT甲级1080 Graduate Admission【模拟】
题目:https://pintia.cn/problem-sets/994805342720868352/problems/994805387268571136 题意: 模拟高考志愿录取. 考生根据总 ...
- 【PAT甲级】1026 Table Tennis (30 分)(结构体排序,trick较多)
题意: 输入一个正整数N(<=10000),表示客户(对)的大小,接着输入N行数据,每行包括一对顾客到场的时间,想要玩的时间,以及是否是VIP客户.接下来输入两个正整数K,M(K<=100 ...
- PAT 甲级 1030 Travel Plan (30 分)(dijstra,较简单,但要注意是从0到n-1)
1030 Travel Plan (30 分) A traveler's map gives the distances between cities along the highways, to ...
- PAT 甲级 1049 Counting Ones (30 分)(找规律,较难,想到了一点但没有深入考虑嫌麻烦)***
1049 Counting Ones (30 分) The task is simple: given any positive integer N, you are supposed to co ...
- PAT 甲级 1026 Table Tennis (30 分)(坑点很多,逻辑较复杂,做了1天)
1026 Table Tennis (30 分) A table tennis club has N tables available to the public. The tables are ...
- PAT 甲级 1072 Gas Station (30 分)(dijstra)
1072 Gas Station (30 分) A gas station has to be built at such a location that the minimum distance ...
随机推荐
- Linux操作系统启动故障排错之"/etc/fstab"文件被删除恢复案例
Linux操作系统启动故障排错之"/etc/fstab"文件被删除恢复案例 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.模拟故障 [root@yinzhe ...
- MySQL/MariaDB数据库的视图(VIEW)
MySQL/MariaDB数据库的视图(VIEW) 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.视图概述 1>.什么是视图 视图就是一个虚拟的表,保存有实表的查询结果 ...
- 调用百度API返回经纬度
后台调用百度API接口生成: import java.io.BufferedReader; import java.io.IOException;import java.io.InputStreamR ...
- Kali和Metasploitable2的网络配置
Kali和Metasploitable2的网络配置 2017年06月19日 16:00:00 weixin_34275734 阅读数 389 原文链接:https://blog.csdn.net/ ...
- linux下写tomcat启动,重启的脚本
启动: #bash/bin cd /finance/ LANG="en_US.UTF-8" export LANG /finance/tomcat8-finance/bin/cat ...
- js实现文本框自动显示两位小数
转自https://blog.csdn.net/qiji2011/article/details/81270552 1.js: //保留2位小数,如:2,会在2后面补上00.即2.00 functio ...
- SpringMVC的全局异常处理
@ControllerAdvice的使用 我们都知道做项目一般都会有全局异常统一处理的类,那么这个类在Spring中可以用@ControllerAdvice来实现. @ControllerAdvice ...
- 【Selenium-WebDriver实战篇】Java丨验证码图片去除干扰像素,方便验证码的识别(转)
参考地址:https://www.cnblogs.com/haojieli/p/6212627.html 1.先来看看效果: 原图 除去干扰像素后 2.解析代码: 1).读取文件夹里面的图片 1 St ...
- django--远程mysql
settings.py中配置 DATABASES = { 'default': { 'ENGINE': 'django.db.backends.mysql', 'NAME': 'ttsx', # 数据 ...
- windows查看端口被占用情况
首先,使用cmd命令打开CMD命令窗口 使用下面的命令来查看某端口被占用的情况,以8035为例: netstat -ano|findstr " 结果如下图: 最后一列的6532为PID号,根 ...