题目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. 【TensorFlow入门完全指南】神经网络篇·自动编码机

    自动编码机(Autoencoder)属于非监督学习,不需要对训练样本进行标记.自动编码机(Autoencoder)由三层网络组成,其中输入层神经元数量与输出层神经元数量相等,中间层神经元数量少于输入层 ...

  2. java面试题(杨晓峰)---第六讲谈谈动态代理是基于什么原理?

    我在编译时不知道,而在运行时知道,那么肯定在运行时给了提示,这个提示就是额外功.好处是可以重复利用相同代码. 代理模式:通过代理静默的解决一些与业务无关的问题,例如远程,安全,事物,日志,资源关闭,. ...

  3. SAP云平台的Document Service

    SAP云平台以微服务的方式提供了Document的CRUD(增删改查)操作.该微服务基于标准的CMIS协议(Content Management Interoperability Service). ...

  4. 使用JDK自带的VisualVM进行Java程序的性能分析

    VisualVM是什么? VisualVM是JDK自带的一个用于Java程序性能分析的工具,JDK安装完毕后就有啦,在JDK安装目录的bin文件夹下能找到名称为jvisualvm.exe. 要使用Vi ...

  5. Java 守护线程(Daemon) 例子

    当我们在Java中创建一个线程,缺省状态下它是一个User线程,如果该线程运行,JVM不会终结该程序.当一个线被标记为守护线程,JVM不会等待其结束,只要所有用户(User)线程都结束,JVM将终结程 ...

  6. WPF知识点全攻略11- 命令(Command)

    先看一下命令的简单使用: <Window.CommandBindings> <CommandBinding Command="ApplicationCommands.Cut ...

  7. SD Card Formatter for Mac Download

    https://www.sdcard.org/downloads/formatter_4/eula_mac/ SDFormatter Mac版是一款Mac OS平台上的sd卡修复工具,SDFormat ...

  8. TDB文件介绍

    samba在运行时,Samba 存储许多信息,从本地密码到希望从中收到信息的一系列客户端.这类数据其中一些是暂时的,在 Samba 重启时可能会被丢弃,但是另一些却是永久的,不会被丢弃.这类数据可能是 ...

  9. C++系统学习之九:顺序容器

    元素在顺序容器中的顺序与其加入容器时的位置相对应.关联容器中元素的位置由元素相关联的关键字值决定.所有容器类都共享公共的接口,不同容器按不同方式对其进行扩展. 一个容器就是一些特定类型对象的集合.顺序 ...

  10. tensorflow目标检测API之建立自己的数据集

    1 收集数据 为了方便,我找了11张月儿的照片做数据集,如图1,当然这在实际应用过程中是远远不够的 2 labelImg软件的安装 使用labelImg软件(下载地址:https://github.c ...