Source:

PAT A1080 Graduate Admission (30 分)

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 G​E​​, and the interview grade G​I​​. 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 G​E​​. 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 G​E​​ and G​I​​, 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", &quota[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的更多相关文章

  1. 题目1005:Graduate Admission

    题目1005:Graduate Admission 时间限制:1 秒 内存限制:32 兆 特殊判题:否 题目描述: It is said that in 2011, there are about 1 ...

  2. 题目1005:Graduate Admission(录取算法)

    题目链接:http://ac.jobdu.com/problem.php?pid=1005 详解链接:https://github.com/zpfbuaa/JobduInCPlusPlus 参考代码: ...

  3. PAT 1080 Graduate Admission[排序][难]

    1080 Graduate Admission(30 分) It is said that in 2011, there are about 100 graduate schools ready to ...

  4. pat1080. Graduate Admission (30)

    1080. Graduate Admission (30) 时间限制 200 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue It ...

  5. pat 甲级 1080. Graduate Admission (30)

    1080. Graduate Admission (30) 时间限制 200 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue It ...

  6. PAT 甲级 1080 Graduate Admission (30 分) (简单,结构体排序模拟)

    1080 Graduate Admission (30 分)   It is said that in 2011, there are about 100 graduate schools ready ...

  7. PAT-1080 Graduate Admission (结构体排序)

    1080. Graduate Admission It is said that in 2013, there were about 100 graduate schools ready to pro ...

  8. 1080 Graduate Admission——PAT甲级真题

    1080 Graduate Admission--PAT甲级练习题 It is said that in 2013, there were about 100 graduate schools rea ...

  9. 1080. Graduate Admission (30)

    时间限制 200 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue It is said that in 2013, there w ...

随机推荐

  1. (10)C++ 使用类

    一.运算符重载 1. #include<iostream> using namespace std; class Sum { int add; public: Sum(int add) { ...

  2. 几个常见的漏洞(xss攻击 cookie未清除 nginx信息泄露)与处理方法

    项目在安全检查中发现很多问题,要求整改,其中就有最常见的xss攻击 漏洞描述 渗透测试人员检测到网站筛选框均存在反射型跨站脚本攻击,例如: "><script>alert( ...

  3. 字母所对应的Unicode编码

    A~Z                65~90 a~z                 97~122 public class Unicode { public static void main(S ...

  4. c# PID算法入门

    离开工控行业已经有一段时间了,最近回忆起以前的工作,又对 PID 算法有了兴趣.所以写了一个小项目,希望可以帮到需要的人,也算是对那段工作经历的一个总结. 这是一个 winform 的项目.负载是一个 ...

  5. Java的部分问题和小结

    2015/9/6 ThreadLocal:该类提供了线程局部变量,这样可以生成对每个线程唯一的局部标识符. 2015/9/18 1.乱码问题:  js:xdata = encodeURI(encode ...

  6. Java删除过期文件

    public static void main(String[] args) throws IOException { long cut = LocalDateTime.now().minusWeek ...

  7. 【记录】API Gateway作用? 与过滤器的区别?Nginx与Zuul区别?

    网关(gateway)的作用: 网关可以拦截客户端所有请求,对该请求进行权限控制.负载均衡.日志管理.接口调用监控等 过滤器与网关的区别是什么? 过滤器是拦截单个tomcat服务器请求. 网关是拦截整 ...

  8. 一、基础项目构建,引入web模块,完成一个简单的RESTful API

    一.Spring Boot的主要优点: 为所有Spring开发者更快的入门 开箱即用,提供各种默认配置来简化项目配置 内嵌式容器简化Web项目 没有冗余代码生成和XML配置的要求 二.使用maven构 ...

  9. Atcoder arc093

    D-Grid Components 在一个100*100的网格图上染色,问黑格四连通块的个数为A,白格四连通块的个数为B的一种构造方案?(A,B<=500) 将整个平面分成50*100的两部分, ...

  10. Goaccess的简单使用

    goaccess了,它是一个日志分析工具,并不只是为nginx使用的,你也可以用它来分析apache,具有解析速度快,使用简单,能生成json,html,csv等特点. 1.goaccess的基本安装 ...