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 ...
随机推荐
- MySQL/MariaDB数据库的复制加密
MySQL/MariaDB数据库的复制加密 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.MySQL的安全问题 1>.基于SSL复制 在默认的主从复制过程或远程连接 ...
- 基于CentOS7配置ArcGIS enterprise
Centos7GUI安装过程 1.右键点击列表中的虚拟主机,打开控制台. 点击绿色开机键,开始安装. 这里有一个很关键的点,就是上一步设置中的打开电源自动连接.一开始设置的时候别忘了. 2.开机后会出 ...
- Python 爬虫js加密破解(三) 百度翻译 sign
第一步: 模拟抓包分析加密参数 第二步: 找到加密字段 调试出来的sign和抓取得到的数据一致,都是 275626.55195 第三部: 分析js加密方法 第四部:运行js代码: 仅供交流学习使用
- destoon下动态链接301到伪静态(ngnix)
分享一个destoon6.0/7.0下动态链接301到伪静态上面,实现权重提升. if ($request_uri ~* "^/index.php\?itemid=(\d+)&mod ...
- pandas 常用方法使用示例
from pandas import DataFrame import numpy as np import pandas as pd t={ , , np.nan, , np.nan, ], &qu ...
- 8-html表格
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta http ...
- 7-html列表
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta http ...
- HTML事件(onclick、onmouseover、onmouseout、this)
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- RSDS pdb格式
本描述了“RSDS”或“DS”类型的pdb(程序数据库)文件的格式,这些文件是由Miscrosoft的link.exe从版本7及更高版本发出的. 什么是PDB文件? 如果选择了/DEBUG选项或/DE ...
- 【批处理】for命令
for 命令 学习:https://www.cnblogs.com/Braveliu/p/5081087.html FOR这条命令基本上都被用来处理文本,但还有其他一些好用的功能! 看看他的基本格式( ...