PAT甲级1080 Graduate Admission【模拟】
题目: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【模拟】的更多相关文章
- 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 (30)
1080. Graduate Admission (30) 时间限制 200 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue It ...
- PAT甲级——A1080 Graduate Admission
It is said that in 2011, there are about 100 graduate schools ready to proceed over 40,000 applicati ...
- 1080 Graduate Admission——PAT甲级真题
1080 Graduate Admission--PAT甲级练习题 It is said that in 2013, there were about 100 graduate schools rea ...
- PAT 1080 Graduate Admission[排序][难]
1080 Graduate Admission(30 分) It is said that in 2011, there are about 100 graduate schools ready to ...
- 【PAT甲级】1080 Graduate Admission (30 分)
题意: 输入三个正整数N,M,K(N<=40000,M<=100,K<=5)分别表示学生人数,可供报考学校总数,学生可填志愿总数.接着输入一行M个正整数表示从0到M-1每所学校招生人 ...
- PAT 1080. Graduate Admission (30)
It is said that in 2013, there were about 100 graduate schools ready to proceed over 40,000 applicat ...
- PAT 1080. Graduate Admission
It is said that in 2013, there were about 100 graduate schools ready to proceed over 40,000 applicat ...
- PAT (Advanced Level) 1080. Graduate Admission (30)
简单题. #include<cstdio> #include<cstring> #include<cmath> #include<vector> #in ...
随机推荐
- 第三天:MDN CSS学习笔记
一:CSS基础 1:DOM 当浏览器显示文档时,它必须将文档的内容与其样式信息结合.它分两个阶段处理文档: 浏览器将 HTML 和 CSS 转化成 DOM (文档对象模型).DOM在计算机内存中表示文 ...
- 单片机成长之路(51基础篇) - 009 关于sdcc的多文件编译范例(一)
本文是续 单片机成长之路(51基础篇) - 006 在Linux下搭建51单片机的开发烧写环境编写的. 本范例主要由(main.c ,delay.h,delay.c,makefile)4个文件组成,s ...
- 简单理解 RPC(转载)
原文地址:http://www.syyong.com/architecture/Simple-understanding-of-RPC.html RPC(Remote Procedure Call P ...
- Linux下通过 rm -f 删除大量文件时报错:Argument list too long
Linux下通过 rm -f 删除大量的小文件时出现类似如下错误信息: -bash: /bin/rm: Argument list too long 如下图所示: 问题原因 如果待删除文件中包含的小 ...
- C++学习的书籍
https://www.ossblog.org/master-c-programming-with-open-source-books/
- ios app qbw.plist demo
qbw.plist <?xml version="1.0" encoding="UTF-8"?><!DOCTYPE plist PUBLIC ...
- 【网络编程】——Lighttpd 返回HTTP/1.1 417 Expectation Failed
最近在使用python 的 pcurl 发送 post 请求到服务端的时候[服务端使用的服务是Lighttpd],发现只要 post 请求的数据超过 1024 之后,就会返回如下错误: * Hostn ...
- 火币网行情获取的websocket客户端
从验证结果看应该是网络关闭了,不过程序写的不错,可以作为其它websocket客户端的测试程序 # !/usr/bin/env python # -*- coding: utf-8 -*- # aut ...
- SpringMVC+ Mybatis 配置多数据源 + 自动数据源切换 + 实现数据库读写分离
现在大型的电子商务系统,在数据库层面大都采用读写分离技术,就是一个Master数据库,多个Slave数据库.Master库负责数据更新和实时数据查询,Slave库当然负责非实时数据查询.因为在实际的应 ...
- Adding ASP.NET MVC5 Identity Authentication to an existing project
Configuring Identity to your existing project is not hard thing. You must install some NuGet package ...