1005.Graduate Admission

Source: Internet
Author: User

Title Description:

It is said, there was about graduate schools ready to proceed over 40,000 applications in Zhejiang Provin Ce. 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'll be a admitted one by one from the top of the rank 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 rank Li St, 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 admit All the applicants and the same rank, even if its quota would be exceeded.

Input:

    Each input file could contain more Than one test case.
    starts with a line containing three positive integers:n (≤40,000), and the total number of appli cants; 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:

    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
#include <iostream>#include<algorithm>using namespacestd;structstudent{intID; intGE; intgi; intchoice[5];};structschool{intquota; Student std[ -]; intfront,rear;};BOOLCMP (Student a,student b) {if(a.ge+a.gi!=b.ge+b.gi)returnA.ge+a.gi>b.ge+B.gi; Else                returnA.ge>b.ge;}BOOLCmpa (Student a,student b) {returna.id<b.ID;} intMain () {intn,m,k; inti,j;  while(cin>>n>>m>>k) {Student std[ -]; School sch[ -];  for(i=0; i!=m;i++) {cin>>Sch[i].quota; Sch[i].front=0; Sch[i].rear=0; }                 for(i=0; i!=n;i++) {cin>>std[i].ge>>Std[i].gi;  for(j=0; j!=k;j++) Cin>>Std[i].choice[j]; Std[i].id=i; } sort (Std,std+n,cmp);  for(i=0; i!=n;i++)                {                         for(j=0; j!=k;j++)                        {                                if(sch[std[i].choice[j]].quota>0) {sch[std[i].choice[j]].std[sch[std[i].choice[ J]].rear++]=Std[i]; Sch[std[i].choice[j]].quota--;  Break; }                                Else if(std[i].ge==sch[std[i].choice[j]].std[sch[std[i].choice[j]].rear-1].ge&&std[i].gi==sch[std[i].choice[j]].std[sch[std[i].choice[j]].rear-1].gi) {Sch[std[i].choice[j]].std[sch[std[i].cho Ice[j]].rear++]=Std[i]; Sch[std[i].choice[j]].quota--;  Break; }                        }                }                 for(i=0; i!=m;i++)                {                        if(sch[i].front==sch[i].rear) cout<<Endl; Else{sort (sch[i].std,sch[i].std+Sch[i].rear,cmpa); cout<<sch[i].std[sch[i].front++].id;  while(sch[i].front!=sch[i].rear) cout<<' '<<sch[i].std[sch[i].front++].id; cout<<Endl; }                        }         }        return 0;}

1005.Graduate Admission

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.