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 ...
随机推荐
- ASP.NET Core学习——6
依赖注入DI ASP.NET Core的底层设计支持和使用依赖注入.ASP.NET Core应用程序可以利用内置的框架服务将它们注入到启动类的方法中,并且应用程序服务能够配置注入. 1.什么是依赖注入 ...
- linux中软连接和硬链接的区别
linux中创建软连接和硬链接的方法: 软连接: ln -s oldfile slink 硬连接: ln oldfile hlink linux中创建软连接和硬链接的区别: 原理上,硬链 ...
- 52、saleforce 第一篇
View the Schema 1.点击setup 2.在QuickFind and Search中输入Schema Builder 先点击clear all 去除所有现实的UML,然后选择Line_ ...
- 51、tf-idf值提取关键词
import testWord2vec2 as tw import tensorflow_util as tu import numpy as np model = tw.load_model() n ...
- Linux内核TSS的使用
参见文章:http://blog.chinaunix.net/uid-22695386-id-272098.html linux2.4之前的内核有进程最大数的限制,受限制的原因是,每一个进程都有自已的 ...
- Python数字类型及数学运算
1.数字类型分为int.float和complex,complex暂时用不到,int和float的相关运算和类型转换如下: >>> 59+12 71 >>> 59- ...
- java 重新学习 (一)
一 垃圾回收特点 1.垃圾回收的工作目标是回收物对象的内存空间,这些内存空间都是jvm堆内存里的空间,垃圾回收器值回收内存资源,对他的物理资源:数据库连接,磁盘I/O等资源则无能为力 2.更快进行垃圾 ...
- 元类,sqlalchemy查询
import sqlalchemy from sqlalchemy.ext.declarative import declarative_base #创建连接实例 db = sqlalchemy.cr ...
- Redis Sentinel 高可用方案
redis 主从复制的问题 Redis主从复制可将主节点数据同步给从节点,从节点此时有两个作用: 1,一旦主节点宕机,从节点作为主节点的备份可以随时顶上来. 2,扩展主节点的读能力,分担主节点读压 ...
- 8、服务发现&服务消费者Feign
spring cloud的Netflix中提供了两个组件实现软负载均衡调用,分别是Ribbon和Feign.上一篇和大家一起学习了Ribbon. Ribbon :Spring Cloud Ribbon ...