题目https://pintia.cn/problem-sets/994805342720868352/problems/994805387268571136

题意:

模拟高考志愿录取。

考生根据总成绩和高考成绩排名。根据排名往下录取,每个人有k个志愿。

如果他填的学校名额没有满,那么就可以被录取。如果他填的学校名额满了,最后一名的排名和这个人是一样的话,就可以被录取。

思路:

直接模拟。

刚开始居然有一个数据超时了,把排序的cmp里面改成传引用居然就过了。

 //#include<bits/stdc++>
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<stdlib.h>
#include<queue>
#include<map>
#include<stack>
#include<set> #define LL long long
#define ull unsigned long long
#define inf 0x3f3f3f3f using namespace std; int n, m, k;
const int maxn = 4e4 + ;
struct student{
int ge, gi;
int id;
int gfinal;
vector<int>apply;
}stu[maxn]; bool cmp(student &a, student &b)
{
if(a.gfinal == b.gfinal){
return a.ge > b.ge;
}
else return a.gfinal > b.gfinal;
} struct school{
int quota;
vector<student>addmit;
}sch[]; bool cmpans(student &a, student &b)
{
return a.id < b.id;
} int main()
{
scanf("%d%d%d", &n, &m, &k);
for(int i = ; i < m; i++){
scanf("%d", &sch[i].quota);
}
for(int i = ; i < n; i++){
stu[i].id = i;
scanf("%d%d%", &stu[i].ge, &stu[i].gi);
stu[i].gfinal = (stu[i].ge + stu[i].gi) / ;
for(int j = ; j < k; j++){
int s;
scanf("%d", &s);
stu[i].apply.push_back(s);
}
}
sort(stu, stu + n, cmp); for(int i = ; i < n; i++){
for(int j = ; j < k; j++){
int s = stu[i].apply[j];
if(sch[s].quota){
sch[s].addmit.push_back(stu[i]);
sch[s].quota--;
break;
}
else{
if(sch[s].addmit.size()){
student lastone = sch[s].addmit.back();
if(lastone.gfinal == stu[i].gfinal && lastone.ge == stu[i].ge){
sch[s].addmit.push_back(stu[i]);
break;
}
}
}
}
} for(int i = ; i < m; i++){
if(sch[i].addmit.size()){
sort(sch[i].addmit.begin(), sch[i].addmit.end(), cmpans);
printf("%d", sch[i].addmit[].id);
for(int j = ; j < sch[i].addmit.size(); j++){
printf(" %d", sch[i].addmit[j].id);
}
}
printf("\n");
} return ;
}

PAT甲级1080 Graduate Admission【模拟】的更多相关文章

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

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

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

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

  3. PAT甲级——A1080 Graduate Admission

    It is said that in 2011, there are about 100 graduate schools ready to proceed over 40,000 applicati ...

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

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

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

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

  6. 【PAT甲级】1080 Graduate Admission (30 分)

    题意: 输入三个正整数N,M,K(N<=40000,M<=100,K<=5)分别表示学生人数,可供报考学校总数,学生可填志愿总数.接着输入一行M个正整数表示从0到M-1每所学校招生人 ...

  7. PAT 1080. Graduate Admission (30)

    It is said that in 2013, there were about 100 graduate schools ready to proceed over 40,000 applicat ...

  8. PAT 1080. Graduate Admission

    It is said that in 2013, there were about 100 graduate schools ready to proceed over 40,000 applicat ...

  9. PAT (Advanced Level) 1080. Graduate Admission (30)

    简单题. #include<cstdio> #include<cstring> #include<cmath> #include<vector> #in ...

随机推荐

  1. 通过Nginx反向代理之后客户端验证码session不一致造成无法验证通过的问题解决

    location / { proxy_pass http://127.0.0.1:9080/app/; proxy_cookie_path /app/ /; proxy_cookie_path /ap ...

  2. BFC 形成条件

    块格式化上下文(Block Formatting Context,BFC) 是Web页面的可视化CSS渲染的一部分,是块盒子的布局过程发生的区域,也是浮动元素与其他元素交互的区域. 下列方式会创建块格 ...

  3. 每天一个linux命令(6):cp

    1.命令简介 cp(Copy file):将源文件复制至目标文件,或将多个源文件复制至目标目录. 2.用法 cp [选项]... [-T] 源文件 目标文件 或:cp [选项]... 源文件... 目 ...

  4. Ubuntu18.04下的模拟神器RetroArch

    安装 直接通过apt安装 sudo add-apt-repository ppa:libretro/stable sudo apt update sudo apt install retroarch ...

  5. 关于Gerrit code review 介绍与安装

    代码审核(Code Review)是软件研发质量保障机制中非常重要的一环,但在实际项目执行过程中,却因为种种原因被Delay甚至是忽略.在实践中,给大家推荐一款免费.开放源代码的代码审查软件Gerri ...

  6. Python-MacOSX下SIP引起的pip权限问题解决方案(非取消SIP机制)

    网上很多资料都是取消SIP机制,安装完再恢复.可是基于用户的权限来安装模块包显得更加合理. 第一种:(推荐)pip install module --user -U http://www.jiansh ...

  7. java.lang.IllegalStateException: Cannot run without an instance id.

    启动springboot,报错:quartz集群报错: Sep 09, 2016 5:33:47 AM org.apache.catalina.core.ApplicationContext log ...

  8. Mongodb常用增删改查语法

    1,新增 新增有两种方式 var Tank = mongoose.model('Tank', yourSchema); var small = new Tank({ size: 'small' }); ...

  9. MySQL字符集详解

    Reference:  https://www.cnblogs.com/wcwen1990/p/6917109.html MySQL字符集详解   一.字符集和校验规则 字符集是一套符合和编码,校验规 ...

  10. Win7 SP1 32位 旗舰版 IE8 快速稳定 纯净优化 无人值守 自动激活 20170518

    一.系统特色 1.采用微软原版旗舰版定制而成. 2.优化系统服务,关闭一些平时很少使用的服务. 3.精简掉一些无用的东西. 4.系统全程离线制作,不包含任何恶意插件,放心使用. 5.右下角时间加上星期 ...