PAT 1080. Graduate Admission (30)

Source: Internet
Author: User
Tags bitset

Graduate Admission (30)

It is said, and there were about graduate schools ready to proceed over 40,000 applications in Zhejiang provi nCE. It would help a lot if you could write a program to automate the admission procedure.

Each applicant would has to provide, 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 is ranked according to their final grades, and would be a admitted one by one from the top of the R Ank list.
    • If There is a tied final grade, the applicants would be ranked according to their national entrance exam grade GE. If still tied, their ranks must be the same.
    • each applicant could have K choices and the admission would be do according to his/her choices:if according to the RAN K list, it is one's turn to be admitted; And if the quota of one ' s most preferred shcool are not exceeded, then one'll be admitted to this school, or one's other Choices'll is considered one by one in order. If one gets rejected by all of the preferred schools, then this unfortunate applicant would be rejected.
    • If there is a tied rank, and If the corresponding applicants be applying to the same school, then that school must ad MIT all the applicants with the same rank, , even if its quota would be exceeded.

Input Specification:

Each input file contains the one test case. Each case starts with a line containing three positive integers:n (<=40,000), and the total number of applicants; M (<=100), the total number of graduate schools; and K (<=5), the number of choices an applicant could have.

In the next line, separated by a space, there is 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 is the applicant ' s GE and GI, respectively. The next K integers represent the preferred schools. For the sake of simplicity, we assume the schools is numbered from 0 to M-1, and the applicants is numbered from 0 To N-1.

Output Specification:

For each test case you should output of 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 is in increasing order and is separated by a space. There must is 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 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
Sample Output:
0 1035 6 72 81 4
1#include <iostream>2#include <vector>3#include <algorithm>4#include <bitset>5 6 using namespacestd;7 8 structApplicant9 {Ten     intID; One     intEgrade; A     intIgrade; -     Doublefinal; -     intchoice[6]; the     intrank; - }; -  -Applicant applicants[40000]; +  - BOOLcmpConstapplicant& LHS,Constapplicant&RHS) + { A     if(Lhs.final = =rhs.final) at         returnLhs. Egrade >RHS. Egrade; -     returnLhs.final >rhs.final; - } -  - intMain () - { in     intApplicantnum, Schoolnum, Choicenum; -CIN >> Applicantnum >> schoolnum >>Choicenum; to     intquota[ -]; +      for(inti =0; i < Schoolnum; i++) -CIN >>Quota[i]; the      for(inti =0; i < Applicantnum; i++) *     { $Applicants[i].id =i;Panax NotoginsengCIN >> Applicants[i]. Egrade >>Applicants[i]. Igrade; -Applicants[i].final = (Applicants[i]. Egrade + applicants[i]. Igrade)/2.0; the          for(intj =0; J < Choicenum; J + +) +CIN >>Applicants[i].choice[j]; A     } theSort (applicants, applicants +Applicantnum, CMP); +     //set the rank of the all applicants -     intFinal=0, egrade=0, rank =1; $      for(inti =0; i < Applicantnum; i++) $     { -         if(applicants[i].final = = Final&&applicants[i]. Egrade = =Egrade) -Applicants[i].rank =rank; the         Else -         {WuyiFinal =applicants[i].final; theEgrade =Applicants[i]. Egrade; -Rank = i +1; WuApplicants[i].rank =rank; -         } About     } $bitset<100000>empty; -vector<int> vec[ -]; -      for(inti =0; i < Schoolnum; i++) -         if(Quota[i] <=0) AEmpty.Set(i); +     inti =0; theRank =1; -      while(1) $     { the         //admit the applicants with same rank the          while(I < Applicantnum&&applicants[i].rank = =rank) the         { the              for(intj =0; J < Choicenum; J + +) -             { in                 if(!Empty[applicants[i].choice[j]]) the                 { thequota[applicants[i].choice[j]]--; About Vec[applicants[i].choice[j]].push_back (applicants[i].id); the                      Break; the                 } the             } +i++; -         } the         if(i = =applicantnum)Bayi              Break; the         Else therank = Applicants[i].rank;//Next Rank -      -          for(intj =0; J < Schoolnum; J + +) the             if(Quota[j] <=0) theEmpty.Set(j); the     } the      for(inti =0; i < Schoolnum; i++) -     { the sort (Vec[i].begin (), Vec[i].end ()); the          for(intj =0; J < Vec[i].size (); J + +) the         {94cout <<Vec[i][j]; the             if(J < Vec[i].size ()-1) thecout <<" "; the         }98cout <<Endl; About     } -}



PAT 1080. Graduate Admission (30)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.