九度题目1005:Graduate Admission_[error] /d:/i_dea/graduatepro/src/main/java/com/hx-程序员宅基地

技术标签: 九度  c++  

May 26, 2016
作者:dengshuai_super
出处:http://blog.csdn.net/dengshuai_super/article/details/51507509
声明:自由转载,转载请注明作者及出处。


题目1005:Graduate Admission

题目描述:

    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.

样例输入:

               //N(≤40,000)申请人的总数; M(≤100)研究生院的总数;
11 6 3         //和K(≤5)一个申请人可能的选择的学校的数量。 
2 1 2 2 2 3    //有M个正整数,第i个整数分别是第i个研究生院的名额
100 100 0 1 2  //然后,N行跟进,每行2 + K个整数,用空格隔开
60 60 2 3 5    //前2个整数分别是申请人的GE和GI。 在下面k个整数代 
100 90 0 3 4   //表的首选学校。我们假设学校被编号从0到M-1,
90 100 1 2 0   //和本申请人的编号从0到N-1。
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 4

样例输出:

         //每所学校的结果必须占据一行,其中包含了学校编号和被
         //录取的申请人的数字编号
0 10
3
5 6 7    //该数字必须是递增的顺序并用空格隔开
2 8
         //如果没有申请人被学校录取,你必须相应的输出一个空行
1 4

代码如下:

/*****************************************************************************
*   九度题目1005:Graduate Admission   
******************************************************************************
*   by Deng shuai May 26 2016
*   http://blog.csdn.net/dengshuai_super
******************************************************************************
*   Copyright (c) 2016, Deng Shuai
*   All rights reserved.
*****************************************************************************/

#include<iostream>
#include<map>
#include<algorithm>
#include<vector>
using namespace std;
typedef struct
{ 
  int GE,GI;
  int wanted[5];//学生想去的学校编号
} student;

map<int,student> info;
int compare(int a,int b);
int main()
{
  int N,M,K;//N:学生数;M:学校数;K:学生的志愿学校数。
  while(cin>>N>>M>>K)
  { 
    int num[100];//记录学校的名额
    int rank[40000];//记录学生的排名
    int temp;//想去的学校
    vector<vector<int> > ivec(M);
    for(int i=0;i<N;i++)
      rank[i]=i;//先将学生的排名按照自己的序号初始化

    for(int i=0;i<M;i++)
      cin>>num[i];//第i个研究生院的名额

    for(int i=0;i<N;i++)
      {
        cin>>info[i].GE>>info[i].GI;//输入第i个学生的GE和GI成绩
        for(int j=0;j<K;j++)
        cin>>info[i].wanted[j];//输入第i个学生的想去的K个学校的编号
      }

        //录取名次排名                  
    for(int i=0;i<N;i++)        
        for(int j=i+1;j<N;j++)
        if(compare(rank[j],rank[i])==1) swap(rank[i],rank[j]);//执行后,rank[i]为学生i的排名

        //录取过程
    for(int i=0;i<N;i++)   
        for(int j=0;j<K;j++)
        {  
          temp=info[rank[i]].wanted[j];
          if(ivec[temp].size()<num[temp]) {ivec[temp].push_back(rank[i]);break;}
          if(ivec[temp].size()>=num[temp])   
           { 
            int last=*(ivec[temp].end()-1);
            if(compare(last,rank[i])==0) {ivec[temp].push_back(rank[i]);break;}
            else continue;
           }//if
         }//for

         //排序并输出
     for(int i=0;i<M;i++)
     {
         if(ivec[i].size()==0) cout<<endl;
         else 
         { 
             sort(ivec[i].begin(),ivec[i].end());
             for(vector<int>::iterator iter=ivec[i].begin();iter!=ivec[i].end();iter++)
                if(iter!=--ivec[i].end()) cout<<*iter<<" ";
                else cout<<*iter<<endl;  
         }//else
      }//for

  }//while
  return 0; 
}//main

//比较a,b两个学生的成绩,如果按照规则a的排名靠前,则返回1;两人并列排名返回0;b排名靠前返回-1.
   int compare(int a,int b)
{ 
   if(info[a].GE+info[a].GI>info[b].GE+info[b].GI) return 1;
   if(info[a].GE+info[a].GI<info[b].GE+info[b].GI) return -1;
   if(info[a].GE+info[a].GI==info[b].GE+info[b].GI&&info[a].GE>info[b].GE) return  1;
   if(info[a].GE+info[a].GI==info[b].GE+info[b].GI&&info[a].GE<info[b].GE) return -1;
   if(info[a].GE+info[a].GI==info[b].GE+info[b].GI&&info[a].GE==info[b].GE) return 0;
}

运行截图:

这里写图片描述

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/dengshuai_super/article/details/51507509

智能推荐

hdu 1229 还是A+B(水)-程序员宅基地

文章浏览阅读122次。还是A+BTime Limit: 2000/1000 MS (Java/Others)Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 24568Accepted Submission(s): 11729Problem Description读入两个小于10000的正整数A和B,计算A+B。...

http客户端Feign——日志配置_feign 日志设置-程序员宅基地

文章浏览阅读419次。HEADERS:在BASIC的基础上,额外记录了请求和响应的头信息。FULL:记录所有请求和响应的明细,包括头信息、请求体、元数据。BASIC:仅记录请求的方法,URL以及响应状态码和执行时间。NONE:不记录任何日志信息,这是默认值。配置Feign日志有两种方式;方式二:java代码实现。注解中声明则代表某服务。方式一:配置文件方式。_feign 日志设置

[转载]将容器管理的持久性 Bean 用于面向服务的体系结构-程序员宅基地

文章浏览阅读155次。将容器管理的持久性 Bean 用于面向服务的体系结构本文将介绍如何使用 IBM WebSphere Process Server 对容器管理的持久性 (CMP) Bean的连接和持久性逻辑加以控制,使其可以存储在非关系数据库..._javax.ejb.objectnotfoundexception: no such entity!

基础java练习题(递归)_java 递归例题-程序员宅基地

文章浏览阅读1.5k次。基础java练习题一、递归实现跳台阶从第一级跳到第n级,有多少种跳法一次可跳一级,也可跳两级。还能跳三级import java.math.BigDecimal;import java.util.Scanner;public class Main{ public static void main(String[]args){ Scanner reader=new Scanner(System.in); while(reader.hasNext()){ _java 递归例题

面向对象程序设计(荣誉)实验一 String_对存储在string数组内的所有以字符‘a’开始并以字符‘e’结尾的单词做加密处理。-程序员宅基地

文章浏览阅读1.5k次,点赞6次,收藏6次。目录1.串应用- 计算一个串的最长的真前后缀题目描述输入输出样例输入样例输出题解2.字符串替换(string)题目描述输入输出样例输入样例输出题解3.可重叠子串 (Ver. I)题目描述输入输出样例输入样例输出题解4.字符串操作(string)题目描述输入输出样例输入样例输出题解1.串应用- 计算一个串的最长的真前后缀题目描述给定一个串,如ABCDAB,则ABCDAB的真前缀有:{ A, AB,ABC, ABCD, ABCDA }ABCDAB的真后缀有:{ B, AB,DAB, CDAB, BCDAB_对存储在string数组内的所有以字符‘a’开始并以字符‘e’结尾的单词做加密处理。

算法设计与问题求解/西安交通大学本科课程MOOC/C_算法设计与问题求解西安交通大学-程序员宅基地

文章浏览阅读68次。西安交通大学/算法设计与问题求解/树与二叉树/MOOC_算法设计与问题求解西安交通大学

随便推点

[Vue warn]: Computed property “totalPrice“ was assigned to but it has no setter._computed property "totalprice" was assigned to but-程序员宅基地

文章浏览阅读1.6k次。问题:在Vue项目中出现如下错误提示:[Vue warn]: Computed property "totalPrice" was assigned to but it has no setter. (found in <Anonymous>)代码:<input v-model="totalPrice"/>原因:v-model命令,因Vue 的双向数据绑定原理 , 会自动操作 totalPrice, 对其进行set 操作而 totalPrice 作为计..._computed property "totalprice" was assigned to but it has no setter.

basic1003-我要通过!13行搞定:也许是全网最奇葩解法_basic 1003 case 1-程序员宅基地

文章浏览阅读60次。十分暴力而简洁的解决方式:读取P和T的位置并自动生成唯一正确答案,将题给测点与之对比,不一样就给我爬!_basic 1003 case 1

服务器浏览war文件,详解将Web项目War包部署到Tomcat服务器基本步骤-程序员宅基地

文章浏览阅读422次。原标题:详解将Web项目War包部署到Tomcat服务器基本步骤详解将Web项目War包部署到Tomcat服务器基本步骤1 War包War包一般是在进行Web开发时,通常是一个网站Project下的所有源码的集合,里面包含前台HTML/CSS/JS的代码,也包含Java的代码。当开发人员在自己的开发机器上调试所有代码并通过后,为了交给测试人员测试和未来进行产品发布,都需要将开发人员的源码打包成Wa..._/opt/bosssoft/war/medical-web.war/web-inf/web.xml of module medical-web.war.

python组成三位无重复数字_python组合无重复三位数的实例-程序员宅基地

文章浏览阅读3k次,点赞3次,收藏13次。# -*- coding: utf-8 -*-# 简述:这里有四个数字,分别是:1、2、3、4#提问:能组成多少个互不相同且无重复数字的三位数?各是多少?def f(n):list=[]count=0for i in range(1,n+1):for j in range(1, n+1):for k in range(1, n+1):if i!=j and j!=k and i!=k:list.a..._python求从0到9任意组合成三位数数字不能重复并输出

ElementUl中的el-table怎样吧0和1改变为男和女_elementui table 性别-程序员宅基地

文章浏览阅读1k次,点赞3次,收藏2次。<el-table-column prop="studentSex" label="性别" :formatter="sex"></el-table-column>然后就在vue的methods中写方法就OK了methods: { sex(row,index){ if(row.studentSex == 1){ return '男'; }else{ return '女'; }..._elementui table 性别

java文件操作之移动文件到指定的目录_java中怎么将pro.txt移动到design_mode_code根目录下-程序员宅基地

文章浏览阅读1.1k次。java文件操作之移动文件到指定的目录_java中怎么将pro.txt移动到design_mode_code根目录下

推荐文章

热门文章

相关标签