题目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. HDU Rabbit and Grass 兔子和草 (Nim博弈)

    思路:简单Nim博弈,只需要将所给的数字全部进行异或,结果为0,则先手必败.否则必胜. #include <iostream> using namespace std; int main( ...

  2. jquery的uploadify插件实现的批量上传V3.2.1版

    你需要如下配置(包括引入文件)HTML: <html xmlns="http://www.w3.org/1999/xhtml"> <head runat=&quo ...

  3. 使用Timer组件实现倒计时

    实现效果: 知识运用:  Timer组件的Enabed属性 实现代码: private void timer1_Tick(object sender, EventArgs e) { DateTime ...

  4. javaweb基础(6)_servlet配置参数

    一.ServletConfig讲解 1.1.配置Servlet初始化参数 在Servlet的配置文件web.xml中,可以使用一个或多个<init-param>标签为servlet配置一些 ...

  5. jfinal的配置文件详解

    1.去官网下载最新的jar包(我这是JFinal-lib-2.2) tomcat+mysql 所需要的jar 2.配置web.xml <filter> <filter-name> ...

  6. BZOJ-1833(数位DP)

    #include <bits/stdc++.h> using namespace std; typedef long long ll; ll a,b; int k[20]; ll dp[2 ...

  7. 【数位dp】bzoj3131: [Sdoi2013]淘金

    思路比较自然,但我要是考场上写估计会写挂:好像被什么不得了的细节苟住了?…… Description 小Z在玩一个叫做<淘金者>的游戏.游戏的世界是一个二维坐标.X轴.Y轴坐标范围均为1. ...

  8. Linux Ptrace 详解

    转 https://blog.csdn.net/u012417380/article/details/60470075 Linux Ptrace 详解 2017年03月05日 18:59:58 阅读数 ...

  9. python2和python3中filter函数

    在python2和python3中filter是不同的,其中在python2中filter返回的是一个list,可以直接使用 >>> a = [1,2,3,4,5,6,7] > ...

  10. Qt的由来和发展

    一.Qt的由来 Haavard Nord 和Eirik Chambe-Eng于1991年开始开发"Qt",1994年3月4日创立公司,早名为Quasar Technologies, ...