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 ...
随机推荐
- HTML&CSS基础-xHtml语法规范
HTML&CSS基础-xHtml语法规范 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.html源码 <!DOCTYPE html> <html> ...
- javascript一个在网页上画线的库
文章;安利一个绘制指引线的JS库leader-line 一个在网页上划线的库感觉很不错.
- HDU4814——数学,模拟进制转换
本题围绕:数学公式模拟进制转换 HDU4814 Golden Radio Base 题目描述 将一个十进制的非负整数转换成E(黄金分割数)进制的数 输入 不大于10^9的非负整数,处理到文件尾 输出 ...
- 通过Python实现mysql查询数据库实例
#coding:utf-8 ''' Created on 2017年10月25日 @author: li.liu ''' import pymysql db=pymysql.connect('loca ...
- javascript Object and new object() object --构造函数
- Hive 内置函数
原文见:https://cwiki.apache.org/confluence/display/Hive/LanguageManual+UDF 1.内置运算符1.1关系运算符 运算符 类型 说明 A ...
- 7-html列表
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta http ...
- SpringMVC_原理(转)
在整个Spring MVC框架中,DispatcherServlet处于核心位置,它负责协调和组织不同组件完成请求处理并返回响应的工作.具体流程为:1)客户端发送http请求,web应用服务器接收到这 ...
- proc near/far
proc是定义子程序的伪指令,位置在子程序的开始处,它和endp分别表示子程序定义的开始和结束两者必须成对出现. far是该子程序的属性,决定调用程序和子程序是否在同一代码段如下:为子程序定义及说明, ...
- 集成omnibus-ctl 开发一个专业的软件包管理工具
前边有转发过来自chef 团队的一篇omnibus-ctl 介绍文章,以下尝试进行项目试用 就是简单的集成,没有多少复杂的操作 环境准备 ruby ruby 使用2.6.3 使用 rbenv 安装,可 ...