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 G~E~, and the interview grade G~I~. The final grade of an applicant is (G~E~ + G~I~) / 2. The admission rules are:
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 G~E~ and G~I~, 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:
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:
0 10 3 5 6 7 2 8 1 4
代码:
#include <stdio.h> #include <stdlib.h> ///按最终成绩排名,如果最终成绩相同,就按考试成绩,如果还相同就排名相同 ///每个人可能有k个选择,如果学校人满了,就不行,如果排名相同都申请一个学校,即使人满了也收下所有人。 typedef struct app app; struct app { int id,ge,gi,fin,where; int choice[5];///志愿 }a[40001]; int n,m,k; int need[101],have[101][400],havenum[101];///need是学校招收人数 have是学校已经招收的人 havenum是学校已经招收的人数 int cmp(const void *a,const void *b) { app *aa = (app *)a,*bb = (app *)b; if(aa -> fin == bb -> fin)return bb -> ge - aa -> ge; return bb -> fin - aa -> fin; } int cmp1(const void *a,const void *b) { return *(int *)a - *(int *)b; } int main() { scanf("%d%d%d",&n,&m,&k); for(int i = 0;i < m;i ++) { scanf("%d",&need[i]); } for(int i = 0;i < n;i ++) { a[i].id = i; scanf("%d%d",&a[i].ge,&a[i].gi); a[i].fin = (a[i].ge + a[i].gi) / 2;///求最终成绩 for(int j = 0;j < k;j ++) { scanf("%d",&a[i].choice[j]); } } qsort(a,n,sizeof(app),cmp);///进行排名 for(int i = 0;i < n;i ++) { int *p = a[i].choice; for(int j = 0;j < k;j ++) { ///如果学校还有空 或者 上一个人和自己排名相同且已经进入该学校 那么就可以进入 if(need[p[j]] - havenum[p[j]] > 0 || i && a[i - 1].fin == a[i].fin && a[i - 1].ge == a[i].ge && a[i - 1].where == p[j]) { have[p[j]][havenum[p[j]] ++] = a[i].id; a[i].where = p[j]; break; } } } for(int i = 0;i < m;i ++) { qsort(have[i],havenum[i],sizeof(int),cmp1); for(int j = 0;j < havenum[i];j ++) { if(j)putchar(‘ ‘); printf("%d",have[i][j]); } putchar(‘\n‘); } }
1080 Graduate Admission (30)(30 分)
原文:https://www.cnblogs.com/8023spz/p/9280894.html