先对学生们进行排序,并且求出对应排名。

对于每一个学生,按照志愿的顺序:

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",&quota[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)-排序的更多相关文章

  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 1080. Graduate Admission (30)

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

  4. 1080. Graduate Admission (30)

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

  5. 1080 Graduate Admission (30)(30 分)

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

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

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

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

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

  8. pat1080. Graduate Admission (30)

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

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

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

随机推荐

  1. November 09th, 2017 Week 45th Thursday

    If we did all the things we are capable of, we would literally astound ourselves. 我们如果尽全力去完成我们能做到的事情 ...

  2. DevExpress09、SimpleButton、CheckButton、DropDownButton、HScrollBar控件和VScrollBar控件

    SimpleButton控件 使用SimpleButton控件, 创建一个Button按钮, 可以通过其Image属性添加图片: 该控件与WinForm自带的Button按钮类似: 效果如下: Che ...

  3. 理解传说中的roll、yaw、pitch

    三维中 Yaw, pitch and roll 的区分(图片)                    yaw 航偏                                         pi ...

  4. PAT B1008 数组元素循环右移问题 (20 分)

    一个数组A中存有N(>)个整数,在不允许使用另外数组的前提下,将每个整数循环向右移M(≥)个位置,即将A中的数据由(A​0​​A​1​​⋯A​N−1​​)变换为(A​N−M​​⋯A​N−1​​A ...

  5. input 内容改变的触发事件

    1. onchange onchange 事件会在域的内容改变时触发.支持的标签<input type="text">, <textarea>, <s ...

  6. php输出js到前端

    echo "<script language='javascript'>";echo "alert('invalid user...');";ech ...

  7. Hadoop Version History and Feature

    Versions and Features Hadoop has seen significant interest over the past few years. This has led to ...

  8. android环境的搭配

    android环境一般采用的是adt bundle 下载地址如下: http://tools.android-studio.org/index.php/adt-bundle-plugin 根据自己jd ...

  9. Linux服务-openssh

    目录 1. 使用 SSH 访问远程命令行 1.1 OpenSSH 简介 1.2 SSH 版本 1.3 SSH 认证方式 1.4 openSSH 的工作模式 1.5 Secure Shell 示例 1. ...

  10. kettle学习笔记(六)——kettle转换步骤

    一.概述 转换步骤分类: 1. 增加新的列 2. 字符串处理 3. 行列变换 4. 排序/排重/字段选择 5. 其他转换步骤 二.增加新的列 1.增加常量列 增加一列常量的列 其它增加列的操作大同小异 ...