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. JAVA学习之面向对象

    面向对象是相对面向过程而言面向过程:强调的是功能行为面向对象:将功能封装进对象,强调具备了功能的对象 不论面向对象还是面向过程都是一种开发思想而已.举一个例子来理解面向对象和面向过程把大象装进冰箱分三 ...

  2. 【转】理解JMX之介绍和简单使用

    原文链接:https://blog.csdn.net/lmy86263/article/details/71037316 近期在项目上需要添加一些功能,想把一个开源工程整合进来,虽说是整合,但是觉得跟 ...

  3. upc组队赛14 Evolution Game【dp】

    Evolution Game 题目描述 In the fantasy world of ICPC there are magical beasts. As they grow, these beast ...

  4. Mysql任意读取客户端文件复现

    本机执行 python rogue_mysql_server.py 目标机器上连接本机数据库 mysql -u root -p -h 本机IP mysql -h 192.168.250.132 -ur ...

  5. Centos7安装 Hadoop(单节点)

    1.Hadoop简介 Hadoop是一个由Apache基金会所开发的开源分布式系统基础框架,使用Java开发,是处理大规模数据的软件平台. Hadoop可以从单一节点扩展到上千节点.用户可以在不了解分 ...

  6. [ERR] 153 - Got a packet bigger than 'max_allowed_packet' bytes

    异常原因: 用客户端导入数据的时候,信息包过大 ,终止了数据导入,需要修改max_allowed_packet 参数 解决方案: 1. sql语句修改( ⚠️重启服务设置会失效) 登陆mysql查看当 ...

  7. XSS注入方式和逃避XSS过滤的常用方法(整理)

    (转自黑吧安全网http://www.myhack58.com/) web前端开发常见的安全问题就是会遭遇XSS注入,而常见的XSS注入有以下2种方式: 一.html标签注入 这是最常见的一种,主要入 ...

  8. 转 jmeter 实现loadrunner init end 功能

    一.JMeter 介绍 Apache JMeter是100%纯JAVA桌面应用程序,被设计为用于测试客户端/服务端结构的软件(例如web应用程序).它可以用来测试静态和动态资源的性能,例如:静态文件, ...

  9. Linux 2.6.x fs/pipe.c local kernel root(kit?) exploit (x86)

    /****************************************************************************** * .:: Impel Down ::. ...

  10. Spring mvc的执行流程

    一个请求匹配前端控制器 DispatcherServlet 的请求映射路径(在 web.xml中指定), WEB 容器将该请求转交给 DispatcherServlet 处理 DispatcherSe ...