博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
九度oj 1005 Graduate Admission
阅读量:6688 次
发布时间:2019-06-25

本文共 4095 字,大约阅读时间需要 13 分钟。

这一题我写了三个半小时。哈哈   哈哈  呸   想死的心都有了。

看了     深受启发,才会出了这一道题

题目描述:

    It is said that in 2011, there are 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:

    • The applicants are ranked according to their final grades, and will be admitted one by one from the top of the rank list.

    • If there is a tied final grade, the applicants will be ranked according to their national entrance exam grade GE. If still tied, their ranks must be the same.
    • Each applicant may have K choices and the admission will be done according to his/her choices: if according to the rank list, it is one's turn to be admitted; and if the quota of one's most preferred shcool is not exceeded, then one will be admitted to this school, or one's other choices will be considered one by one in order. If one gets rejected by all of preferred schools, then this unfortunate applicant will be rejected.
    • If there is a tied rank, and if the corresponding applicants are applying to the same school, then that school must admit all the applicants with the same rank, even if its quota will be exceeded.

输入:

    Each input file may contain more than 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.

输出:

    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.

#include 
#include
using namespace std; struct stu{ int num; int GE; int GL; int ave; int select[5]; //志愿 int elected; //录取结果}; struct school{ int Quota; //名额 int ave; //平均分数线 int GE; //GE分数线 int amount;}; bool cmp1(const stu a,const stu b){ if(a.ave!=b.ave) return a.ave>b.ave; //当平均分不等时,按平均值排序(从大到小) else return a.GE>b.GE; //否则按GE} bool cmp2(const stu a,const stu b){ return a.num
>n>>m>>k) { school* mschool=new school[m]; stu* stud=new stu[n]; for(int i=0; i
>mschool[i].Quota; mschool[i].ave=-1; //分数线 mschool[i].GE=-1; //分数线 mschool[i].amount=0; } for(int i=0; i
>stud[i].GE>>stud[i].GL; stud[i].ave=(stud[i].GE+stud[i].GL)/2; for(int j=0; j
>stud[i].select[j]; stud[i].elected=-1; } sort(stud,stud+n,cmp1); //按平均成绩和GE成绩排序 for(int i=0; i
0) { if(mschool[NUM].Quota==1) //只有当school的名额为1是才记录该学生的成绩,作为录取分数线 { mschool[NUM].ave=stud[i].ave; mschool[NUM].GE=stud[i].GE; } stud[i].elected=NUM; //记录该学生的录取结果 mschool[NUM].Quota--; mschool[NUM].amount++; break;//啊啊啊!注意!!被录取后该同学应该跳出循环,不能再被其他大学录取 } else if(mschool[NUM].Quota==0) { if(stud[i].ave==mschool[NUM].ave&&stud[i].GE==mschool[NUM].GE) { stud[i].elected=NUM; mschool[NUM].amount++; break;//啊啊啊!注意!!被录取后该同学应该跳出循环,不能再被其他大学录取 } else mschool[NUM].Quota--; } } } sort(stud,stud+n,cmp2);//为了升序输出 for(int i=0; i

转载于:https://www.cnblogs.com/zhanyeye/p/9746126.html

你可能感兴趣的文章
Java strictfp
查看>>
新建jsp项目
查看>>
numpy.loadtxt()
查看>>
Chrome 调用vue.js 记录
查看>>
将float转换为数据类型numeric时出现算术溢出错误
查看>>
Sqlserver2008R2配置数据库镜像之我的经验总结
查看>>
RDS经典网络平滑迁移到VPC的混访方案
查看>>
svg矢量图制作工具(Sketsa SVG Editor) v7.1.1 中文免费版
查看>>
洛谷P2761 软件补丁问题(状压DP,SPFA)
查看>>
[osg][opengl]透视投影的参数Perspective
查看>>
总结!!!!!
查看>>
SpringBoot入门(三)——入口类解析
查看>>
Spring Boot系列——Spring Boot如何启动
查看>>
NIO之Charset类字符编码对象
查看>>
vue 父子组件传值的另外一种方式 provide inject
查看>>
关于ListBox在Grid中无法充满的问题
查看>>
【 Tomcat 】tomcat8.0 基本参数调优配置
查看>>
Android P的APP适配总结,让你快人一步
查看>>
Spring Boot 的 WEB 项目打包成的 JAR 包,打包成 docker 镜像基本步骤
查看>>
Table 'performance_schema.session_variables' doesn't exist
查看>>