大致题意就是有N个学生,有M个学校,每个学校的名额都是正整数。每个学生可以填K个学校志愿,N个学生一起排名以后,排名高的学生先挑学校,不保护一志愿。

题目要求:

首先,把所有学生按总成绩SUM(GE+GI)递减排序,如果SUM相同,那么就按GE递减排序。

然后,根据成绩确定所有学生的名次。如果当前学生与上一个学生的SUM和GE相同,那么当前学生与上一个学生的名次也相同。

确定所有学生的名次以后,从排名第一名的学生的第一个志愿学校开始。

如果该学校有名额,或者该学校没名额了但是该学生与该学校录取的最后一个学生的名次一样,那么就录取这名学生。

否则,该学生继续找下一个志愿学校,直到能找到能被录取的学校(该学校名额减一),或者所有志愿学校找完都无法被录取。

所有学生的志愿学校都找完以后,每个学校按要求递增输出学生编号。(具体不再赘述)

STL:set容器及其函数,sort函数,auto智能指针。

注意点:学生排序以后,学生id与数组i可能不一致了。代码中的last应该存放i(当前访问的学生),而不是学生id。

 #include"iostream"
#include"set"
#include"algorithm"
using namespace std;
struct Student {
int GE,GI,SUM;//考研成绩,面试成绩,总分
int id;//学生编号
int RANK;//排名
int choices[];//k<=5个志愿
} stu[]; struct School {
int quota;//学校名额
set<int> ID;//录取学生编号,set可以自动排序
int last = -;//标记最后一个被录取学生的编号
} sch[]; bool cmp(const Student& a,const Student& b) { //采用引用变量执行更快
if(a.SUM != b.SUM)
return a.SUM > b.SUM;
else
return a.GE > b.GE;
} int main() {
int N,M,K;
scanf("%d%d%d",&N,&M,&K);
for(int i = ; i < M; ++i) {
scanf("%d",&sch[i].quota);
}
for(int i = ; i < N; ++i) {
scanf("%d%d",&stu[i].GE,&stu[i].GI);
for(int j = ; j < K; ++j) {//K个志愿
scanf("%d",&stu[i].choices[j]);
}
stu[i].id = i;//学生id
stu[i].SUM = stu[i].GE + stu[i].GI;//总成绩
}
sort(stu,stu+N,cmp);//对学生进行排名,排序以后id与i就可能不一致了
for(int i = ; i < N; ++i) {//设置每个学生的名次
if(i > && stu[i].SUM == stu[i-].SUM && stu[i].GE == stu[i-].GE) //如果两个学生的SUM和GE相同,那么他们的名次也相同
stu[i].RANK = stu[i-].RANK;
else
stu[i].RANK = i;
}
for(int i = ; i < N; ++i) {
for(int j = ; j < K; ++j) {
int choice = stu[i].choices[j];//当前学生的当前志愿
int last = sch[choice].last;//最后一个被录取的学生
//学校有名额,或者该学校录满了但该学生与已录取的最后一个学生的名次一样时
if(sch[choice].quota > || stu[i].RANK == stu[last].RANK) {
sch[choice].ID.insert(stu[i].id);//录入学生 id
sch[choice].last = i;//记录当前访问了的学生,之前i写成了stu[i].id导致测试点1,2未通过,妹的!!!
sch[choice].quota--;//名额减一
break;
}
}
}
for(int i = ; i < M; ++i) {
int t = sch[i].ID.size();
if(t > ) {
//auto 是C++11里面的新特性,可以让编译器根据初始值类型直接推断变量的类型
for(auto it = sch[i].ID.begin(); it!=sch[i].ID.end(); ++it) {
printf("%d",*it);
if(t-- > ) {
printf(" ");
}
}
}
printf("\n");
}
return ;
}

  

1080 Graduate Admission的更多相关文章

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

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

  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 分) (简单,结构体排序模拟)

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

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

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

  5. 1080. Graduate Admission (30)

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

  6. PAT 1080. Graduate Admission (30)

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

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

  10. PAT甲级1080 Graduate Admission【模拟】

    题目:https://pintia.cn/problem-sets/994805342720868352/problems/994805387268571136 题意: 模拟高考志愿录取. 考生根据总 ...

随机推荐

  1. SpringCloud学习之—Eureka集群搭建

    Eureka集群的搭建 上次说过了在SpringCloud应用中使用Eureka注册中心,用来对服务提供者进行服务注册与发现,但同时,它也是一个"微服务",单个应用使用空间有限,因 ...

  2. C# bubble sort,selection sort,insertion sort

    static void Main(string[] args) { InsertionSortDemo(); Console.ReadLine(); } static void InsertionSo ...

  3. hive中parquet存储格式数据类型timestamp的问题

    当存储格式为parquet 且 字段类型为 timestamp 且 数据用hive执行sql写入. 这样的字段在使用impala读取时会少8小时.建议存储为sequence格式或者将字段类型设置为st ...

  4. O2O外卖玩众包 开放平台难解标准之痛

    开放平台难解标准之痛" title="O2O外卖玩众包 开放平台难解标准之痛">  有一种怪现象一直是国内互联网企业摆脱不了的附骨之疽--不管规模大小,总是削尖了脑 ...

  5. VUE中使用XLSX实现导出excel表格

    简介 项目中经常会用导出数据的场景,这里介绍 VUE 中如何使用插件 xlsx 导出数据 安装 ## 1.使用 npm 或 yarn 安装依赖(三个依赖) npm install -S file-sa ...

  6. 剑指offer-面试题34-二叉树中和为某一值的路径-二叉树遍历

    /* 题目: 输入一颗二叉树和一个整数,打印从根节点到叶子节点中所有和为该整数的路径. */ /* 思路: 先序遍历,深度遍历. 从树根开始,记录路径之和,遍历到叶子节点,如果和为期望值,则输出. 回 ...

  7. ISE post-place&route仿真准备

    ISE post-place&route仿真准备 使用目的:post-place&route仿真是综合后考虑门延时而进行的仿真.因为考虑到各个门的延时,所以可以发现行为仿真(behav ...

  8. Lodash是什么?

    lodash:是一个一致性.模块化.高性能的 JavaScript 实用工具库.(也就是相当于自己封装的私有方法) node里引入 // Load the full build. var _ = re ...

  9. 剑指offer-面试题17-打印从1到最大的n位数-数字

    /* 题目: 输入数字n,按顺序打印从1到最大的n位十进制数. 如输入3,打印从1,2,3到999. */ /* 思路: 大数问题转化为字符串或数组. */ #include<iostream& ...

  10. 性能优化 && 用户体验

    性能优化 下拉菜单那种最好是点击时候请求,或者是查询时候请求 分页加载 用户体验 有加载.进度条.友好提示