1080. Graduate Admission (30)-排序
先对学生们进行排序,并且求出对应排名。
对于每一个学生,按照志愿的顺序:
1.如果学校名额没满,那么便被该学校录取,并且另vis[s][app[i].ranks]=1,表示学校s录取了该排名位置的学生。
2.如果该学校名额已满,那么看看vis[s][app[i].ranks]是否为1,若是,则表明学校有录取过和他排名一样的学生,那么该学生也能被录取。
否则,学生未录取。
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string.h>
#include <vector> using namespace std;
const int maxn=;
const int maxschool=;
int quota[maxschool];
vector<int> res[maxschool];
int app_school[maxn];
int vis[maxschool][maxn]; //vis[s][i]=1表示学校s有录取rank为i的学生
struct Applicant{
int id;
int ranks;
int GE,GI;
float grades;
int choose[];
bool operator<(const Applicant tmp)const{
if(grades==tmp.grades){
return GE>tmp.GE;
}
else
return grades>tmp.grades;
}
}app[maxn]; int main()
{
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++){
scanf("%d %d",&app[i].GE,&app[i].GI);
for(int j=;j<k;j++){
scanf("%d",&app[i].choose[j]);
}
app[i].id=i;
app[i].grades=(app[i].GE+app[i].GI)/2.0f;
}
sort(app,app+n);
int cnt=;
for(int i=;i<n;i++){
app[i].ranks=++cnt;
for(int j=i+;j<n;j++){
if(app[i].grades==app[j].grades && app[i].GE==app[j].GE){
app[j].ranks=cnt;
i++;
}
}
} //for(int i=0;i<n;i++){
// printf("ranks:%d %d %f %d\n",app[i].GE,app[i].GI,app[i].grades,app[i].ranks);
//}
memset(vis,,sizeof(vis));
int lastSchool=;
int last=;
for(int i=;i<n;i++){
app_school[i]=-;
int j;
for(j=;j<k;j++){
int s=app[i].choose[j];
if(quota[s]>){
quota[s]--;
res[s].push_back(app[i].id);
//lastSchool=s;
//last=i;
app_school[i]=s;
//printf("app:%d school:%d\n",app[i].id,s);
vis[s][app[i].ranks]=;
break;
}
else{
//只要有rank一样的选了这所学校,即使没有名额,那么该生也可以被录取
if(vis[s][app[i].ranks]){
app_school[i]=s;
res[s].push_back(app[i].id);
break;
}
}
}
}
for(int i=;i<m;i++){
int num=res[i].size();
if(num==)
printf("\n");
else{
sort(res[i].begin(),res[i].end());
printf("%d",res[i][]);
for(int j=;j<num;j++){
printf(" %d",res[i][j]);
}
printf("\n");
}
}
return ;
}
1080. Graduate Admission (30)-排序的更多相关文章
- 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 1080. Graduate Admission (30)
It is said that in 2013, there were about 100 graduate schools ready to proceed over 40,000 applicat ...
- 1080. Graduate Admission (30)
时间限制 200 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue It is said that in 2013, there w ...
- 1080 Graduate Admission (30)(30 分)
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 ...
- 【PAT甲级】1080 Graduate Admission (30 分)
题意: 输入三个正整数N,M,K(N<=40000,M<=100,K<=5)分别表示学生人数,可供报考学校总数,学生可填志愿总数.接着输入一行M个正整数表示从0到M-1每所学校招生人 ...
- pat1080. Graduate Admission (30)
1080. Graduate Admission (30) 时间限制 200 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue It ...
- PAT 1080 Graduate Admission[排序][难]
1080 Graduate Admission(30 分) It is said that in 2011, there are about 100 graduate schools ready to ...
随机推荐
- webpack分离css单独打包
这篇文章过期了,webpack4.x已经不这么用了,最新的可以看这个地址webpack实战场景系列 原文地址:http://www.izhongxia.com/posts/44724.html CHA ...
- Sublime Test 3 搭建C++11编译环境(Windows)
0. 我的环境: Windows 8.1,Sublime Test 3 - Build 3126,CodeBlocks 16.01. 1. 下载Sublime Test 3,以及安装Package和各 ...
- Python代码小片段
1.前面变量值的改变不影响后面变量的调用 index=1 index,a=2,index+1 print(a,index) #2 2 2.类的继承(子类实例如何调用父类同名方法) class a: d ...
- Redis系列二:reids介绍
一.什么是redis.redis有哪些特性.redis有哪些应用场景.redis的版本 1. 什么是redis redis是一种基于键值对(key-value)数据库,其中value可以为string ...
- Docker技术入门与实战 第二版-学习笔记-3-Dockerfile 指令详解
前面已经讲解了FROM.RUN指令,还提及了COPY.ADD,接下来学习其他的指令 5.Dockerfile 指令详解 1> COPY 复制文件 格式: COPY <源路径> .. ...
- JAVA框架 Spring 依赖注入
一:介绍 情景:我们在给程序分层的时候:web层.业务层.持久层,各个层之间会有依赖.比如说:业务层和持久层,业务层的代码在调用持久层的时候,传统方式:new 持久层类. 进而进行调用,这种方式会导致 ...
- Android 给TextView中的字体加上“中间线”
大家都知道在做购物App或者购物网站的时候,商品价格往往会有一个“现价”和“原价”而原价往往会在中间加上一个黑色的横线.便于醒目客户,但是这种效果在App中应该怎样做呢? 废话不多少,直接给大家看代码 ...
- php中经常使用的string函数
strpos() ---返回字符串在另一字符串中首次出现的位置 strrpos() ---查找字符串在另一字符串中最后出现的位置 strchr() === strstr() ---找到字符 ...
- Kubernetes学习之路(二十一)之网络模型和网络策略
目录 Kubernetes的网络模型和网络策略 1.Kubernetes网络模型和CNI插件 1.1.Docker网络模型 1.2.Kubernetes网络模型 1.3.Flannel网络插件 1.4 ...
- libgdx学习记录20——多线程MultiThread资源处理
在libgdx中,一般的逻辑流程都在rende()函数中执行,这个函数是由opengl的渲染线程调用的,一般的图形显示和逻辑处理都在这个线程中. 一般情形下,在这个线程中处理就行了.但是当某些逻辑处理 ...