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

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

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. leaflet学习一 入门

    1从官网https://leafletjs.com/下载的Leaflet包含文件: leaflet.js - 简化版的 Leaflet JavaScript代码 leaflet-src.js - 这是 ...

  2. 一些安卓模拟器的IP问题和getOutputStream();关于connect();的函数异常的问题

    ip问题 1.不能使用local host 和127.0.0.1作为本地服务器的地址,而网上无论10.0.0.2还是10.0.2.2的8080端口都无法访问.真正的地址应该在CMD 键入ipconfi ...

  3. 抓取js动态生成的数据分析案例

    需求:爬取https://www.xuexi.cn/f997e76a890b0e5a053c57b19f468436/018d244441062d8916dd472a4c6a0a0b.html页面中的 ...

  4. Java中Map根据键值(key)或者值(value)进行排序实现

    我们都知道,java中的Map结构是key->value键值对存储的,而且根据Map的特性,同一个Map中 不存在两个Key相同的元素,而value不存在这个限制.换句话说,在同一个Map中Ke ...

  5. Android Studio中新建和引用assets文件

    从eclipse转过的朋友们应该不太习惯AS中新建assets文件和对文件内容的引用.我也查找了网上很多资料发现很少有这样的解决答案,于是便把自己解决的方法总结在这里. 1.一般新建project后这 ...

  6. SQL 字符串分割表函数

    --字符串分割表函数 ) ) declare @i int; declare @count int; ); ); declare @Index int; )) declare @rowID int; ...

  7. HDU 1269 迷宫城堡(判断有向图强连通分量的个数,tarjan算法)

    迷宫城堡 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submis ...

  8. (转)LVS+Keepalived使用总结 vip丢失

    /sbin/ifconfig lo: $vip broadcast $vip netmask 255.255.255.255 up /sbin/ifconfig lo: 172.16.254.63 b ...

  9. Json.NET如何避免循环引用

    Json.NET在将对象序列化为Json字符串的时候,如果对象有循环引用的属性或字段,那么会导致Json.NET抛出循环引用异常. 有两种方法可以解决这个问题: 1.在对象循环引用的属性上打上[Jso ...

  10. cf244D. Match &amp; Catch 字符串hash (模板)或 后缀数组。。。

    D. Match & Catch 能够用各种方法做.字符串hash.后缀数组,dp.拓展kmp,字典树.. . 字符串hash(模板) http://blog.csdn.net/gdujian ...