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.app
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:ide
Input Specification:this
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.spa
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.code
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.blog
Output Specification:three
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 4Sample Output:
0 10 3 5 6 7 2 8 1 4
1 #include<stdio.h> 2 #include<math.h> 3 #include<stdlib.h> 4 #include<string.h> 5 #include<algorithm> 6 using namespace std; 7 8 struct app 9 { 10 int id, ge, gi, f, r; 11 int choice[10]; 12 }a[40010]; 13 14 struct school 15 { 16 int quota, num, lastAdmit; 17 int stu_id[40010]; 18 }s[110]; 19 20 bool cmp1(app x, app y) 21 { 22 if(x.f != y.f) 23 return x.f > y.f; 24 else 25 return x.ge > y.ge; 26 } 27 28 bool cmp2(int x, int y) 29 { 30 return a[x].id < a[y].id; 31 } 32 33 int main() 34 { 35 int n, m, k, i, j; 36 scanf("%d%d%d", &n, &m, &k); 37 for(i = 0; i < m; i++) 38 { 39 scanf("%d", &s[i].quota); 40 s[i].num = 0; 41 s[i].lastAdmit = -1; 42 } 43 44 for(i = 0; i < n; i++) 45 { 46 scanf("%d%d", &a[i].ge, &a[i].gi); 47 a[i].id = i; 48 a[i].f = a[i].ge + a[i].gi; 49 for(j = 0; j < k; j++) 50 { 51 scanf("%d", &a[i].choice[j]); 52 } 53 } 54 sort(a, a + n, cmp1); 55 for(i = 0; i < n; i ++) 56 { 57 if(i > 0 && a[i].f == a[i - 1].f && a[i].ge == a[i - 1].ge) 58 { 59 a[i].r = a[i - 1].r; 60 } 61 else 62 { 63 a[i].r = i; 64 } 65 } 66 for(i = 0; i < n; i++) 67 { 68 for(j = 0; j < k; j++) 69 { 70 int cho = a[i].choice[j]; 71 int number = s[cho].num; 72 int last = s[cho].lastAdmit; 73 if(number < s[cho].quota || (last != -1 && a[i].r == a[last].r)) 74 { 75 s[cho].stu_id[number] = i; 76 s[cho].lastAdmit = i; 77 s[cho].num++; 78 break; 79 } 80 } 81 } 82 for(i = 0; i < m; i++) 83 { 84 if(s[i].num > 0) 85 { 86 sort(s[i].stu_id, s[i].stu_id + s[i].num, cmp2); 87 for(j = 0; j < s[i].num; j++) 88 { 89 printf("%d", a[s[i].stu_id[j]].id); 90 if(j < s[i].num - 1) 91 { 92 printf(" "); 93 } 94 } 95 } 96 printf("\n"); 97 } 98 return 0; 99 }