PAT 1080-Graduate Admission (30)
来源:互联网 发布:淘宝收藏店铺上限 编辑:程序博客网 时间:2024/06/06 02:09
时间限制 1000 ms 内存限制 65536 KB 代码长度限制 100 KB 判断程序 Standard
题目描述
It is said that in 2013, there were about 100 graduate schools ready to proceed over 40,000 applications in Zhejiang Province. It would help a lot if you could write a program to automate the admission procedure.Each applicant will have to provide two grades: the national entrance exam grade GE, and the interview grade GI. The final grade of an applicant is (GE + GI) / 2. The admission rules are:
输入描述:
Each input file contains one test case. Each case starts with a line containing three positive integers: N (<=40,000), the total number of applicants; M (<=100), the total number of graduate schools; and K (<=5), the number of choices an applicant may have.In the next line, separated by a space, there are M positive integers. The i-th integer is the quota of the i-th graduate school respectively.Then N lines follow, each contains 2+K integers separated by a space. The first 2 integers are the applicant's GE and GI, respectively. The next K integers represent the preferred schools. For the sake of simplicity, we assume that the schools are numbered from 0 to M-1, and the applicants are numbered from 0 to N-1.
输出描述:
For each test case you should output the admission results for all the graduate schools. The results of each school must occupy a line, which contains the applicants' numbers that school admits. The numbers must be in increasing order and be separated by a space. There must be no extra space at the end of each line. If no applicant is admitted by a school, you must output an empty line correspondingly.
输入例子:
11 6 32 1 2 2 2 3100 100 0 1 260 60 2 3 5100 90 0 3 490 100 1 2 090 90 5 1 380 90 1 0 280 80 0 1 280 80 0 1 280 70 1 3 270 80 1 2 3100 100 0 2 4
输出例子:
0 1035 6 72 81 4
解题思路
该题目模拟学生志愿录取的过程,有以下三个要点。
1. 排名按照综合分数,若综合分数一样则按照笔试成绩,若笔试成绩一样则排名相同。
2. 若排名相同的n人选择了同一学校,而该学校还有余量,则必须录取这n人,即使录取后超出学校录取容量。
3. 学生按照志愿的先后顺序录取,若该志愿还有余量或者满足条件2则被录取,否则按照顺序查看下一志愿是否满足条件。
按照上面三个条件我们很容易建立模型,题目的重点即是排序和要点2的实现,详见代码。
#include<iostream>#include<vector>#include<algorithm>using namespace std;int N, M, K;struct score{int id;int E;int T;float F;int choice[5];};struct school{int std;int quota;vector<int> adm;//admission student};vector<school> sch;vector<score> apc;//applicationbool cmp(score a, score b){if (a.F != b.F)return a.F > b.F;return a.E > b.E;}int main(){cin >> N >> M >> K;sch.resize(M);apc.resize(N);for (int i = 0; i < M; i++)cin >> sch[i].quota;for (int i = 0; i < N; i++){apc[i].id = i;cin >> apc[i].E >> apc[i].T;apc[i].F = (float(apc[i].E) + float(apc[i].T)) / 2;for (int j = 0; j < K; j++)cin >> apc[i].choice[j];}sort(apc.begin(), apc.begin() + N, cmp);int tempchoice;for (int i = 0; i < N; i++){for (int j = 0; j < K; j++){if (sch[apc[i].choice[j]].quota > 0 ||(apc[sch[apc[i].choice[j]].std].F == apc[i].F && apc[sch[apc[i].choice[j]].std].E == apc[i].E)){sch[apc[i].choice[j]].quota--;sch[apc[i].choice[j]].std = i;sch[apc[i].choice[j]].adm.push_back(apc[i].id);break;}}}for (int i = 0; i < M; i++){int num = sch[i].adm.size();sort(sch[i].adm.begin(), sch[i].adm.begin() + num);if (num == 0)cout << endl;else{for (int j = 0; j < num - 1; j++)cout << sch[i].adm[j] << " ";cout << sch[i].adm[num - 1] << endl;}}//system("pause");return 0;}
0 0
- PAT 1080-Graduate Admission (30)
- PAT 1080 Graduate Admission
- PAT 1080Graduate Admission
- pat 1080 Graduate Admission
- PAT 1080. Graduate Admission (30)
- PAT 1080. Graduate Admission (30)
- PAT 1080. Graduate Admission (30)
- 【PAT】1080. Graduate Admission (30)
- 1080. Graduate Admission (30) PAT
- PAT 1015Graduate Admission (30)
- pat-1080. Graduate Admission (30)
- pat-A1080. Graduate Admission (30)
- PAT A1080. Graduate Admission (30)
- PAT A1080 graduate admission (30)
- PAT A1080. Graduate Admission (30)
- PAT (Advanced Level) Practise 1080 Graduate Admission (30)
- PAT (Advanced Level) Practise 1080 Graduate Admission (30)
- Pat(Advanced Level)Practice--1080(Graduate Admission)
- 试水用markdown写博客
- js中innerText/value/innerHTML三个属性的区别
- 训练20-HTML 给图像设置圆角边框
- android 服务service
- PAT (Advanced Level) 1126. Eulerian Path (25) 解题报告
- PAT 1080-Graduate Admission (30)
- iOS推送通知的证书设置
- springmvc框架报错java.lang.IllegalArgumentException: No converter found for return value of type: class
- GYM 100030 D.Broadcasting(水~)
- JavaBean简单及使用
- linux环境下整合nginx1.8.0和tomcat7负载均衡配置
- 得到分页列表的分页数据
- 图书管理程序管理员界面
- 【TensorFlow】tf.nn.conv2d是怎样实现卷积的?