标签:
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:
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: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 <iostream> 2 #include <vector> 3 #include <algorithm> 4 #include <bitset> 5 6 using namespace std; 7 8 struct Applicant 9 { 10 int id; 11 int EGrade; 12 int IGrade; 13 double final; 14 int choice[6]; 15 int rank; 16 }; 17 18 Applicant applicants[40000]; 19 20 bool cmp(const Applicant& lhs, const Applicant& rhs) 21 { 22 if (lhs.final == rhs.final) 23 return lhs.EGrade > rhs.EGrade; 24 return lhs.final > rhs.final; 25 } 26 27 int main() 28 { 29 int applicantNum, schoolNum, choiceNum; 30 cin >> applicantNum >> schoolNum >> choiceNum; 31 int quota[100]; 32 for (int i = 0; i < schoolNum; i++) 33 cin >> quota[i]; 34 for (int i = 0; i < applicantNum; i++) 35 { 36 applicants[i].id = i; 37 cin >> applicants[i].EGrade >> applicants[i].IGrade; 38 applicants[i].final = (applicants[i].EGrade + applicants[i].IGrade) / 2.0; 39 for (int j = 0; j < choiceNum; j++) 40 cin >> applicants[i].choice[j]; 41 } 42 sort(applicants, applicants + applicantNum, cmp); 43 //set the rank of the all applicants 44 int final=0, EGrade=0, rank = 1; 45 for (int i = 0; i < applicantNum; i++) 46 { 47 if (applicants[i].final == final&&applicants[i].EGrade == EGrade) 48 applicants[i].rank = rank; 49 else 50 { 51 final = applicants[i].final; 52 EGrade = applicants[i].EGrade; 53 rank = i + 1; 54 applicants[i].rank = rank; 55 } 56 } 57 bitset<100000> empty; 58 vector<int> vec[100]; 59 for (int i = 0; i < schoolNum; i++) 60 if (quota[i] <= 0) 61 empty.set(i); 62 int i = 0; 63 rank = 1; 64 while (1) 65 { 66 //admit the applicants with same rank 67 while (i < applicantNum&&applicants[i].rank == rank) 68 { 69 for (int j = 0; j < choiceNum; j++) 70 { 71 if (!empty[applicants[i].choice[j]]) 72 { 73 quota[applicants[i].choice[j]]--; 74 vec[applicants[i].choice[j]].push_back(applicants[i].id); 75 break; 76 } 77 } 78 i++; 79 } 80 if (i == applicantNum) 81 break; 82 else 83 rank = applicants[i].rank; //next rank 84 85 for (int j = 0; j < schoolNum; j++) 86 if (quota[j] <= 0) 87 empty.set(j); 88 } 89 for (int i = 0; i < schoolNum; i++) 90 { 91 sort(vec[i].begin(), vec[i].end()); 92 for (int j = 0; j < vec[i].size(); j++) 93 { 94 cout << vec[i][j]; 95 if (j < vec[i].size() - 1) 96 cout << " "; 97 } 98 cout << endl; 99 } 100 }
PAT 1080. Graduate Admission (30)
标签:
原文地址:http://www.cnblogs.com/jackwang822/p/4733230.html