A1080 Graduate Admission (30 point(s))

排序后按名次选学校

1. 原文

原题

It is said that in 2011, there are 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:

  • The applicants are ranked according to their final grades, and will be admitted one by one from the top of the rank list.
  • If there is a tied final grade, the applicants will be ranked according to their national entrance exam grade GE. If still tied, their ranks must be the same.
  • Each applicant may have K choices and the admission will be done according to his/her choices: if according to the rank list, it is one’s turn to be admitted; and if the quota of one’s most preferred shcool is not exceeded, then one will be admitted to this school, or one’s other choices will be considered one by one in order. If one gets rejected by all of preferred schools, then this unfortunate applicant will be rejected.
  • If there is a tied rank, and if the corresponding applicants are applying to the same school, then that school must admit all the applicants with the same rank, even if its quota will be exceeded.

Input Specification:

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.

output Specification:

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.

Sample Input:

1
2
3
4
5
6
7
8
9
10
11
12
13
11 6 3
2 1 2 2 2 3
100 100 0 1 2
60 60 2 3 5
100 90 0 3 4
90 100 1 2 0
90 90 5 1 3
80 90 1 0 2
80 80 0 1 2
80 80 0 1 2
80 70 1 3 2
70 80 1 2 3
100 100 0 2 4

Sample output:

1
2
3
4
5
6
0 10
3
5 6 7
2 8

1 4

2. 解析

结构体记录每个申请者的信息

1
2
int id,exam,interview,final;
int chioce[7];

根据final,exam排序

根据排名选学校

当申请者的final,exam都相同时,学校破格录取。

cnt[] 学校实际招收人数

quota[] 学校录取人数

1
2
3
if (cnt[pos]<quota[pos]||
(school[pos][lastnode].final==v[i].final&&
school[pos][lastnode].exam==v[i].exam))

3. AC代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#include<cstdio>
#include<algorithm>
#include<vector>
using namespace std;
struct node{
int id,exam,interview,final;
int chioce[7];
};
vector<node> v;
int quota[110]={};
int cnt[110]={};
bool cmp(node a,node b){
if (a.final!=b.final)
{
return a.final>b.final;
}else{
return a.exam>b.exam;
}
}
vector<node> school[110];
bool cmp2(node a,node b){
return a.id<b.id;
}
int main(){
int n,m,k;
scanf("%d%d%d",&n,&m,&k);
for (int i = 0; i < m; ++i)
{
scanf("%d",&quota[i]);
}
node temp;
for (int i = 0; i < n; ++i)
{
temp.id=i;
scanf("%d%d",&temp.exam,&temp.interview);
temp.final=temp.exam+temp.interview;
for (int j = 0; j < k; ++j)
{
scanf("%d",&temp.chioce[j]);
}
v.push_back(temp);
}
sort(v.begin(),v.end(),cmp);
for (int i = 0; i < n; ++i)
{
for (int j = 0; j < k; ++j)
{
int pos=v[i].chioce[j];
int lastnode=cnt[pos]-1;
if (cnt[pos]<quota[pos]||
(school[pos][lastnode].final==v[i].final&&
school[pos][lastnode].exam==v[i].exam))
{
school[pos].push_back(v[i]);
cnt[pos]++;
break;
}
}
}
for (int i = 0; i < m; ++i)
{
sort(school[i].begin(),school[i].end(),cmp2);
for (int j = 0; j < cnt[i]; ++j)
{
printf("%d",school[i][j].id);
if (j<cnt[i]-1)
{
printf(" ");
}
}
printf("\n");
}
return 0;
}
本文结束  感谢您的阅读
  • 本文作者: Wang Ting
  • 本文链接: /zh-CN/2019/09/03/A1080/
  • 发布时间: 2019-09-03 12:32
  • 更新时间: 2021-10-29 14:04
  • 版权声明: 本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!