Title Link: http://ac.jobdu.com/problem.php?pid=1005
Detailed Links: https://github.com/zpfbuaa/JobduInCPlusPlus
Reference code:
////1005 Graduate Admission.cpp//Jobdu////Created by Pengfei_zheng on 27/04/2017.//copyright©2017 Pengfei_zheng. All rights reserved.//#include<stdio.h>#include<iostream>#include<algorithm>#include<string.h>#include<cmath>#defineCHOOSE 6#defineMax_size 40001#defineSCHOOL 101using namespacestd;intN, M, K;structapply{intGE; intgi; DoubleGF; intChoose[choose]; intID; BOOL operator< (ConstApply &a)Const{ if(GF! =A.GF) { returnGF >A.GF; } Else if(GE! =a.ge) { returnGE >a.ge; } Else { returnGE >a.ge; } }};structschool{intquota; intRealnum; intappid[max_size];}; Apply Apply[max_size]; School School[school]; intMain () { while(SCANF ("%d%d%d", &n,&m,&k)! =EOF) { for(inti =0; I < m; i++) {scanf ("%d",&School[i].quota); School[i].realnum=0; } for(inti =0; I < n; i++) {scanf ("%d%d",&apply[i].ge,&apply[i].gi); APPLY[I].GF=(Double) (APPLY[I].GE+APPLY[I].GI)/2.0; for(intj =0; J < K; J + +) {scanf ("%d",&Apply[i].choose[j]); } apply[i].id=i; } sort (Apply,apply+N); intSID; for(inti =0; I < n; i++){ for(intj =0; J < K; J + +) {SID=Apply[i].choose[j]; if(School[sid].quota >0) {School[sid].appid[school[sid].realnum]=i; School[sid].realnum++; School[sid].quota--; Break; } Else{ intLastID = school[sid].appid[school[sid].realnum-1]; if(APPLY[I].GF = = APPLY[LASTID].GF && apply[i].ge = =apply[lastid].ge) {School[sid].appid[school[sid].realnum]=i; School[sid].realnum++; School[sid].quota--; Break; } } } } for(inti =0; I < m; i++){ for(intj =0; J < School[i].realnum; J + +) {School[i].appid[j]=apply[school[i].appid[j]].id; } } for(inti =0; I < m; i++){ if(school[i].realnum==0) {printf ("\ n"); } Else if(school[i].realnum==1) {printf ("%d\n", school[i].appid[0]); } Else{sort (school[i].appid,school[i].appid+school[i].realnum); BOOLFirst =true; for(intj =0; J < School[i].realnum; J + +){ if(first==true) { First=false; } Else{printf (" "); } printf ("%d", School[i].appid[j]); } printf ("\ n"); } } } return 0;}/************************************************************** problem:1005 User:zpfbuaa language:c++ R esult:accepted time:0 Ms memory:19180 kb****************************************************************/
Topic 1005:graduate Admission (admission algorithm)