PAT_A1080#Graduate Admission
Source:
Description:
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
Keys:
- 模拟题
Attention:
- 利用结构体排序,需要注意id与新排名位序的映射,PAT的测试不太严格,可以参考牛客网最后一个测例
Code:
/*
Data: 2019-07-14 18:26:36
Problem: PAT_A1080#Graduate Admission
AC: 39:42 题目大意:
初试Ge,复试Gi,总分(Ge+Gi)/2
按照总分,初试,依次排名;
K个志愿,按照学校招生名额依次录取
相同排名且相同志愿的考生,无论招生名额是否已满,都要录取
输入:
第一行给出,考生数N<=4e4,学校数M<=1e2,志愿数K<=5
接下来一行,各学校的招生名额(0~m-1)
接下来N行,Ge,Gi,K个志愿
输出:
各学校的录取结果,考生号递增(0~n-1)
未招生则打印空行 基本思路:
静态存储考生信息,用考生编号替代数据项排名
创建学校录取信息的列表,按照排名依次录取
*/ #include<cstdio>
#include<vector>
#include<algorithm>
using namespace std;
const int N=1e5,M=,K=;
struct node
{
int ge,gi,g;
int se[K];
}info[N];
int quota[M],link[N];
vector<int> sch[M]; bool cmp(const int &a, const int &b)
{
if(info[a].g != info[b].g)
return info[a].g > info[b].g;
else
return info[a].ge > info[b].ge;
} int main()
{
#ifdef ONLINE_JUDGE
#else
freopen("Test.txt", "r", stdin);
#endif int n,m,k;
scanf("%d%d%d", &n,&m,&k);
for(int i=; i<m; i++)
scanf("%d", "a[i]);
for(int i=; i<n; i++)
{
link[i]=i;
scanf("%d%d", &info[i].ge,&info[i].gi);
for(int j=; j<k; j++)
scanf("%d", &info[i].se[j]);
info[i].g = info[i].ge + info[i].gi;
}
sort(link,link+n,cmp);
for(int i=; i<n; i++)
{
int id = link[i];
for(int j=; j<k; j++)
{
int cho = info[id].se[j];
int len = sch[cho].size();
if(len < quota[cho]){
sch[cho].push_back(id);
break;
}
else{
int stu = sch[cho][len-];
if(info[stu].g==info[id].g && info[stu].ge==info[id].ge){
sch[cho].push_back(id);
break;
}
}
}
}
for(int i=; i<m; i++)
{
sort(sch[i].begin(),sch[i].end());
for(int j=; j<sch[i].size(); j++)
printf("%d%c", sch[i][j],j==sch[i].size()-?'\n':' ');
if(sch[i].size() == )
printf("\n");
} return ;
}
结构体排序:
#include<cstdio>
#include<vector>
#include<algorithm>
using namespace std;
const int STU=5e4,SCH=,SLT=;
struct node
{
int id,gi,ge;
int select[SLT];
}stu[STU];
int quo[SCH];
vector<int> adm[SCH]; bool cmp(const node &a, const node &b)
{
if(a.gi+a.ge != b.gi+b.ge)
return a.gi+a.ge > b.gi+b.ge;
else
return a.ge > b.ge;
} bool cmp2(const int &a, const int &b)
{
return stu[a].id < stu[b].id;
} int main()
{
#ifdef ONLINE_JUDGE
#else
freopen("Test.txt", "r", stdin);
#endif // ONLINE_JUDGE int n,m,k;
scanf("%d%d%d", &n,&m,&k);
for(int i=; i<m; i++)
scanf("%d", &quo[i]);
for(int i=; i<n; i++)
{
scanf("%d%d", &stu[i].ge,&stu[i].gi);
stu[i].id = i;
for(int j=; j<k; j++)
scanf("%d", &stu[i].select[j]);
}
sort(stu,stu+n,cmp);
for(int i=; i<n; i++)
{
for(int j=; j<k; j++)
{
int sch=stu[i].select[j];
if(adm[sch].size() < quo[sch])
{
adm[sch].push_back(i);
break;
}
else
{
int num = adm[sch].size();
int last = adm[sch][num-];
if(stu[last].gi==stu[i].gi && stu[last].ge==stu[i].ge)
{
adm[sch].push_back(i);
break;
}
}
}
}
for(int i=; i<m; i++)
{
sort(adm[i].begin(),adm[i].end(),cmp2);
for(int j=; j<adm[i].size(); j++)
printf("%d%c", stu[adm[i][j]].id,j==adm[i].size()-?'\n':' ');
if(adm[i].size()==)
printf("\n");
} return ;
}
PAT_A1080#Graduate Admission的更多相关文章
- 题目1005:Graduate Admission
题目1005:Graduate Admission 时间限制:1 秒 内存限制:32 兆 特殊判题:否 题目描述: It is said that in 2011, there are about 1 ...
- 题目1005:Graduate Admission(录取算法)
题目链接:http://ac.jobdu.com/problem.php?pid=1005 详解链接:https://github.com/zpfbuaa/JobduInCPlusPlus 参考代码: ...
- PAT 1080 Graduate Admission[排序][难]
1080 Graduate Admission(30 分) It is said that in 2011, there are about 100 graduate schools ready to ...
- pat1080. 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) 时间限制 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 (结构体排序)
1080. Graduate Admission It is said that in 2013, there were about 100 graduate schools ready to pro ...
- 1080 Graduate Admission——PAT甲级真题
1080 Graduate Admission--PAT甲级练习题 It is said that in 2013, there were about 100 graduate schools rea ...
- 1080. Graduate Admission (30)
时间限制 200 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue It is said that in 2013, there w ...
随机推荐
- STM32 系统架构
这里所讲的 STM32 系统架构主要针对的 STM32F103 这些非互联型芯片 STM32 主系统主要由四个驱动单元和四个被动单元构成. 四个驱动单元是: 内核 DCode 总线; 系统总线;通用 ...
- HTML-参考手册: HTML 全局属性
ylbtech-HTML-参考手册: HTML 全局属性 1.返回顶部 1. HTML 全局属性 New : HTML5 新属性. 属性 描述 accesskey 设置访问元素的键盘快捷键. clas ...
- python学习笔记:操作Excle
import xlwt #写excel import xlrd #读excel import xlutils #修改excel 一.写操作 1.写Excel import xlwt #写excel,导 ...
- java 重新学习 (二)
一.栈内存里的引用变量并未真正存储对象的成员变量,对象的成员变量数据实际存放在堆内存中,而引用变量只是指向该堆内存里的对象. 二.堆内存里的对象可以有多个引用,若果堆内存中没有变量指向该对象,程序无法 ...
- python之正则表达式【re】
在处理字符串时,经常会有查找符合某些规则的字符串的需求.正则表达式就是用于藐视这些规则的工具.换句话说,正则表达式是记录文本规则的代码. 1.行定位符. 行定位符就是用来表示字符串的边界,“^”表示开 ...
- HBase版本进化史及大版本特性
HBase 2.0 新特性介绍 2018年4月30日HBase发布了2.0的Release版本.HBase的2.0版本承载了太多的Features,共包含4551个Issues,可以说是迄今最大的一个 ...
- spark性能调优05-troubleshooting处理
1.调节reduce端缓冲区大小避免OOM异常 1.1 为什么要调节reduce端缓冲区大小 对于map端不断产生的数据,reduce端会不断拉取一部分数据放入到缓冲区,进行聚合处理: 当map端数据 ...
- Java技术专区-虚拟机系列-类加载机制(类的初始化)
类加载的生命周期: 加载 -> 验证 -> 准备 -> 解析 -> 初始化 -> 使用 -> 卸载 加载 -> 验证 -> 准备 -& ...
- ollvm 编译
ollvm 的编译相对 llvm 更简单, 1:下载ollvm代码,去 https://github.com/obfuscator-llvm/obfuscator/tree/llvm-4.0 下载,并 ...
- 理解Java GC日志
idea 在vm options处加入-XX:+PrintGCDetails,可打印GC日志. public class ReferenceCountingGC { public Object ins ...