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 ...
随机推荐
- php 字符串 定界符 json_last_error()
字符串的3种赋值 1:单引号 $str = '111111111111 '; 2:双引号 $str =" 11111111111 "; 3:定界符 $str = <<& ...
- 使用JQuery对页面进行绑值
使用JQuery对页面进行绑值 <!DOCTYPE html> <html> <head> <meta charset="UTF-8"&g ...
- linux 杂七杂八
一."init"是内核启动的第一个用户空间程序(PID=1),也是所有用户态进程的"大总管":所有内核态进程的大总管是PID=2的[kthreadd]: 二.v ...
- java 并发——ReentrantLock
java 并发--ReentrantLock 简介 public class ReentrantLock implements Lock, java.io.Serializable { // 继承了 ...
- 数据转化之JSON
1.定义:Json(JavaScript Object Notation)是一种轻量级的数据教换模式,简单来说就是javascript中的对象和数组,所以这两种结构就是对象和数组两种结构,通过这两种结 ...
- css篇-页面布局-三栏布局
页面布局 题目:假设高度已知,请写出三栏布局,其中左栏.右栏宽度各为300px,中间自适应. 1)浮动 2)绝对定位 3)Flexbox 4)表格布局 5)网格布局(CSS3的Grid布局) 代码: ...
- js实现页面跳转的几种方法小结
地址:https://www.jb51.net/article/84335.htm 地址:https://blog.csdn.net/tsoteo/article/details/77849403
- jdk紧急漏洞,XMLDecoder反序列化攻击
昨天在公司发现了一个jdk中的XMLDecoder反序列化的漏洞,看起来很危险!下面通过两个示例来看看这个漏洞的危害! 示例1:利用XmlDecoder删除本地文件 首先来看这个xmldecoder. ...
- 为什么要用webpack!
为什么要用webpack? 现今的很多网页其实可以看做是功能丰富的应用,它们拥有着复杂的JavaScript代码和一大堆依赖包. 模块化,让我们可以把复杂的程序细化为小的文件; 类似于Type ...
- 解决.Net MVC 中出现 非介入式客户端验证规则中的验证类型名称必须唯一。下列验证类型出现重复: required 的bug
最近在开动科技创新作品的开发,出现了一个让人很烦恼的错误,每次从浏览页跳转到编辑页时就会出现一下错误 非介入式客户端验证规则中的验证类型名称必须唯一.下列验证类型出现重复: required 上一下出 ...