题目1005:Graduate Admission

时间限制:1 秒

内存限制:32 兆

特殊判题:

提交:6182

解决:1791

题目描述:                       

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.

样例输入:                       
11 6 3
2 1 2 2 2 3
100 100 0 1 2
60 60 2 3 5
100 90 0 3 4
90 100 1 2 0
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 此题坑比较多
第一,输出时每行末尾不能有空格
第二,输出时如果某学校未录取学生则为空行
第三,输出时每个学校录取的学生按从小到大输出 代码如下:
 #include <cstdio>
#include <cstdlib>
#include <algorithm>
using namespace std; struct Applicant{
int GE;
int GI;
int choices[];
int num;
}; /*int compare(const void *x0, const void *y0)
{
Applicant x = *(Applicant *)x0;
Applicant y = *(Applicant *)y0;
int gradeX = x.GE + x.GI;
int gradeY = y.GE + y.GI;
if(gradeX > gradeY) {
return -1;
}
else if(gradeX < gradeY) {
return 1;
}
else {
if(x.GE > y.GE) {
return -1;
}
else if(x.GE < y.GE) {
return 1;
}
else {
return 0;
}
}
}*/ int compare(const void *x0, const void *y0)
{
Applicant x = *(Applicant *)x0;
Applicant y = *(Applicant *)y0;
int gradeX = x.GE + x.GI;
int gradeY = y.GE + y.GI;
if(gradeX == gradeY) {
return y.GE > x.GE;
}
else {
return gradeY > gradeX;
}
} int compare2(const void *x0, const void *y0) {
return *(int *)x0 - *(int *)y0;
} bool Equal(Applicant a,Applicant b)
{
if(a.GE==b.GE&&a.GI==b.GI)
return true;
return false;
} Applicant apply[];
int ok[][];
Applicant score[]; int main() {
int M, N, K;
//N <= 40000 M <= 100 K <= 5
int quota[];
int man[];
//freopen("input.txt","r",stdin);
while(scanf("%d %d %d",&N, &M, &K) != EOF) {
for(int i = ; i < M; i++) {
scanf("%d",&quota[i]);
man[i] = ;
}
for(int i = ; i < N; i++) {
scanf("%d %d",&apply[i].GE, &apply[i].GI);
for(int j = ; j < K; j++) {
scanf("%d",&apply[i].choices[j]);
}
apply[i].num = i;
}
//have read Matrix
qsort(apply, N, sizeof(Applicant),compare);
//sort /* printf("\n");
for(int i = 0; i < N; i++) {
printf("%d %d ",apply[i].GE, apply[i].GI);
for(int j = 0; j < K; j++) {
printf("%d ",apply[i].choices[j]);
}
printf("\n");
}
printf("\n");*/ for(int i = ; i < N; i++) {
for(int j = ; j < K; j++) {
int school = apply[i].choices[j];
if(quota[school] == ) {
continue;//next choice
}
if(man[school] < quota[school]) {
ok[school][man[school]] = apply[i].num;
score[school].GE = apply[i].GE;
score[school].GI=apply[i].GI;
man[school]++;
break;//next person
}
else if(man[school] > ){
int lastS = ok[school][man[school]-];
//此处lastS记录的是num,是原来的顺序
//而此时数组已经排序,换了一个顺序,所以用lastS就会出错
bool flag = Equal(apply[i],score[school]);
if(flag == true) {
//puts("ok");
ok[school][man[school]] = apply[i].num;
score[school].GE = apply[i].GE;
score[school].GI=apply[i].GI;
man[school]++;
break;//next person
} }
}
}
for(int i = ; i < M; i++) {
qsort(ok[i],man[i],sizeof(int),compare2);
for(int k = ; k < man[i] - ; k++) {
printf("%d ",ok[i][k]);
}
if(man[i] != ) {
printf("%d",ok[i][man[i]-]);
}
printf("\n");
}
}
return ;
}

这到题做错了多次,开始令我百思不得其解。经过反复检查,发现出错点在与79行的lastS,开始比较Equal用的是apply[i]和apply[lastS],但此处lastS是排序前的num值,并不是排序后数组的下标。后来去记录每一学校最后录取一人的成绩,问题得以解决。

九度oj 1005的更多相关文章

  1. 九度OJ 1005:Graduate Admission (排序)

    时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:5646 解决:1632 题目描述: It is said that in 2011, there are about 100 graduat ...

  2. hdu 1284 关于钱币兑换的一系列问题 九度oj 题目1408:吃豆机器人

    钱币兑换问题 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Sub ...

  3. 九度oj 题目1007:奥运排序问题

    九度oj 题目1007:奥运排序问题   恢复 题目描述: 按要求,给国家进行排名. 输入:                        有多组数据. 第一行给出国家数N,要求排名的国家数M,国家号 ...

  4. 九度oj 题目1087:约数的个数

    题目链接:http://ac.jobdu.com/problem.php?pid=1087 题目描述: 输入n个整数,依次输出每个数的约数的个数 输入: 输入的第一行为N,即数组的个数(N<=1 ...

  5. 九度OJ 1502 最大值最小化(JAVA)

    题目1502:最大值最小化(二分答案) 九度OJ Java import java.util.Scanner; public class Main { public static int max(in ...

  6. 九度OJ,题目1089:数字反转

    题目描述: 12翻一下是21,34翻一下是43,12+34是46,46翻一下是64,现在又任意两个正整数,问他们两个数反转的和是否等于两个数的和的反转. 输入: 第一行一个正整数表示测试数据的个数n. ...

  7. 九度OJ 1500 出操队形 -- 动态规划(最长上升子序列)

    题目地址:http://ac.jobdu.com/problem.php?pid=1500 题目描述: 在读高中的时候,每天早上学校都要组织全校的师生进行跑步来锻炼身体,每当出操令吹响时,大家就开始往 ...

  8. 九度OJ 1531 货币面值(网易游戏2013年校园招聘笔试题) -- 动态规划

    题目地址:http://ac.jobdu.com/problem.php?pid=1531 题目描述: 小虎是游戏中的一个国王,在他管理的国家中发行了很多不同面额的纸币,用这些纸币进行任意的组合可以在 ...

  9. 九度OJ 1024 畅通工程 -- 并查集、贪心算法(最小生成树)

    题目地址:http://ac.jobdu.com/problem.php?pid=1024 题目描述:     省政府"畅通工程"的目标是使全省任何两个村庄间都可以实现公路交通(但 ...

随机推荐

  1. Python3+Selenium3+webdriver学习笔记12(js操作应用:滚动条 日历 内嵌div)

    #!/usr/bin/env python# -*- coding:utf-8 -*-'''Selenium3+webdriver学习笔记12(js操作应用:滚动条 日历 内嵌div)'''from ...

  2. Python+selenium之fixtures

    fixtures即可以表示测试用例的开始和结束,也可以表示测试类和测试模块的开始和结束. import unittest def setUpModule(): print("test mod ...

  3. 2013年省市区/县数据SQL Server(SQL语句)

    SET ANSI_NULLS ONGOSET QUOTED_IDENTIFIER ONGOSET ANSI_PADDING ONGOCREATE TABLE [dbo].[tbl_Region]( [ ...

  4. 使用github进行代码托管

    ---恢复内容开始--- 记录下使用github进行个人代码托管,github是公共的代码托管库,可以免费使用,由于是公共的所以大家都可以查看,如果是隐私重要的文件代码可以选择付费变为私有库 1.注册 ...

  5. ABAP,Java和JavaScript的序列化,反序列化

    ABAP 1. ABAP提供了一个工具类cl_proxy_xml_transform,通过它的两个方法abap_to_xml_xstring和xml_xstring_to_abap实现两种格式的互换. ...

  6. [学习笔记] C++ 历年试题解析(二)--程序题

    发现程序题也挺有价值的. 顺便记录下来几道. 1.题目 #include <iostream> #include <cstring> using namespace ① std ...

  7. 【转】iOS开发里的Bundle是个啥玩意?!

    初学iOS开发的同学,不管是自己写的,还是粘贴的代码,或多或少都写过下面的代码 [[NSBundle mainBundle] pathForResource:@"someFileName&q ...

  8. Java基础 匿名内部类 异常 多线程 集合面试题

    匿名内部类:没有名字的内部类.就是内部类的简化形式.一般只用一次就可以用这种形式.匿名内部类其实就是一个匿名子类对象.想要定义匿名内部类:需要前提,内部类必须继承一个类或者实现接口. 匿名内部类的格式 ...

  9. [提供可行性脚本] RHEL/CentOS 7 多节点SSH免密登陆

    实验说明: 在自动化部署时,会经常SSH别的机器去操作,然而每次的密码认证却很令人烦躁,尤其是很长的密码,因此SSH免密登陆就显得必不可少: 在机器数目很多的时候,使用更过的往往是Ansible分发并 ...

  10. linux系统入门—文件管理

    目录 linux系统入门-文件管理 系统目录结构 目录管理 linux系统入门-文件管理 系统目录结构 几乎所有的计算机操作系统都是使用目录结构组织文件.具体来说就是在一个目录中存放子目录和文件,而在 ...