九度oj 1005
题目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","a[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的更多相关文章
- 九度OJ 1005:Graduate Admission (排序)
时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:5646 解决:1632 题目描述: It is said that in 2011, there are about 100 graduat ...
- hdu 1284 关于钱币兑换的一系列问题 九度oj 题目1408:吃豆机器人
钱币兑换问题 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Sub ...
- 九度oj 题目1007:奥运排序问题
九度oj 题目1007:奥运排序问题 恢复 题目描述: 按要求,给国家进行排名. 输入: 有多组数据. 第一行给出国家数N,要求排名的国家数M,国家号 ...
- 九度oj 题目1087:约数的个数
题目链接:http://ac.jobdu.com/problem.php?pid=1087 题目描述: 输入n个整数,依次输出每个数的约数的个数 输入: 输入的第一行为N,即数组的个数(N<=1 ...
- 九度OJ 1502 最大值最小化(JAVA)
题目1502:最大值最小化(二分答案) 九度OJ Java import java.util.Scanner; public class Main { public static int max(in ...
- 九度OJ,题目1089:数字反转
题目描述: 12翻一下是21,34翻一下是43,12+34是46,46翻一下是64,现在又任意两个正整数,问他们两个数反转的和是否等于两个数的和的反转. 输入: 第一行一个正整数表示测试数据的个数n. ...
- 九度OJ 1500 出操队形 -- 动态规划(最长上升子序列)
题目地址:http://ac.jobdu.com/problem.php?pid=1500 题目描述: 在读高中的时候,每天早上学校都要组织全校的师生进行跑步来锻炼身体,每当出操令吹响时,大家就开始往 ...
- 九度OJ 1531 货币面值(网易游戏2013年校园招聘笔试题) -- 动态规划
题目地址:http://ac.jobdu.com/problem.php?pid=1531 题目描述: 小虎是游戏中的一个国王,在他管理的国家中发行了很多不同面额的纸币,用这些纸币进行任意的组合可以在 ...
- 九度OJ 1024 畅通工程 -- 并查集、贪心算法(最小生成树)
题目地址:http://ac.jobdu.com/problem.php?pid=1024 题目描述: 省政府"畅通工程"的目标是使全省任何两个村庄间都可以实现公路交通(但 ...
随机推荐
- WinForm 窗体API移动 API阴影
窗体移动 //窗体移动API [DllImport("user32.dll")] public static extern bool ReleaseCapture(); [DllI ...
- Nginx FastCGI PHP
We can see this comment in nginx.conf. # pass the PHP scripts to FastCGI server listening on 127.0.0 ...
- UVA 11732 strcmp() Anyone (Trie+链表)
先两两比较,比较次数是两者相同的最长前缀长度*2+1,比较特殊的情况是两者完全相同时候比较次数是单词长度*2+2, 两个单词'末尾\0'和'\0'比较一次,s尾部'\0'和循环内'\0'比较一次. 因 ...
- JAVA并发编程:相关概念及VOLATILE关键字解析
一.内存模型的相关概念 由于计算机在执行程序时都是在CPU中运行,临时数据存在主存即物理内存,数据的读取和写入都要和内存交互,CPU的运行速度远远快于内存,会大大降低程序执行的速度,于是就有了高速缓存 ...
- UIViewController 的 edgesForExtendedLayout、automaticallyAdjustsScrollViewInsets属性
1.有时你命名设置了某控件的y坐标为0,确总是被导航栏遮挡住,如下: UILabel *label = [[UILabel alloc] init]; label.text = @"请 ...
- VueJS坎坷之路222--vue cli 3.0引入静态文件
前两天准备搭建一个vue小项目,当引入jquery脚本的时候一直找不到引入的文件: 在网上搜了好多vue添加静态文件的方法,发现大多数方法都是创建一个与文件夹src同等级的文件夹static存放引入的 ...
- 【Git版本控制】GitHub上fork项目和clone项目的区别
fork:在github页面,点击fork按钮,将别人的仓库复制一份到自己的仓库. clone:直接将github中的仓库克隆到自己本地电脑中 问题1:pull request的作用 比如在仓库的主人 ...
- Voyager如何使用Compass
Compass由Resources,Commands,Logs三个部分组成 Resources包含了Links和Fonts: Commands可以执行php命令,比如创建model: 创建一个Down ...
- day2-python 登录
# username = 'niuhanyang' # 写一个判断登录的程序: # 输入: username # password # 最大错误次数是3次,输入3次都没有登录成功,提示错误次数达到上限 ...
- day 37 MySQL行(记录)的详细操作
MySQL行(记录)的详细操作 阅读目录 一 介绍 二 插入数据INSERT 三 更新数据UPDATE 四 删除数据DELETE 五 查询数据SELECT 六 权限管理 一 介绍 MySQL数据操 ...