九度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 题目描述: 省政府"畅通工程"的目标是使全省任何两个村庄间都可以实现公路交通(但 ...
随机推荐
- Protocol Buffer学习教程之语法手册(二)
1.说明 此向导介绍如何使用protocol buffer language创建一个自己的protocolbuffer文件,包括语法与如何通过“.proto”文件生成数据访问的类,此处只介绍proto ...
- 【LeetCode】2.Add Two Numbers 链表数相加
题目: You are given two linked lists representing two non-negative numbers. The digits are stored in r ...
- TC和脚本语言
TC:Turbo C 集成开发环境是由Borland 公司开发的一套C 语言开发工具,它集成了程序编辑.调试.链接等多种功能.在DOS 系统时代,Turbo C 是被最广泛使用的一种PC 机应用程序开 ...
- UVALive 4329 Ping pong (BIT)
枚举中间的人,只要知道在这个人前面的技能值比他小的人数和后面技能值比他小的人数就能计算方案数了,技能值大的可有小的推出. 因此可以利用树状数组,从左到右往树上插点,每个点询问sum(a[i]-1)就是 ...
- 设置DdtaGridView控件中网格线的样式
实现效果: 知识运用: DataGridView控件的GridColor属性 //用来获取或设置网格线的颜色 public Color GridColor { get; set; } //属性值: C ...
- Python 进程 线程总结
操作系统的底层是 进程 线程 实现的 进程 操作系统完成系统进程的切换,中间有状态的保存.进程有自己独立的空间,进程多,资源消耗大 进程是最小的资源管理单位 可以理解为盛放线程的容器 线程 线程是最小 ...
- 微信iOS多设备多字体适配方案总结
一.背景 2014下半年,微信iOS版先后适配iPad, iPhone6/6plus.随着这些大屏设备的登场,部分用户觉得微信的字体太小,但也有很多用户不喜欢太大的字体.为了满足不同用户的需求,我们做 ...
- FTP服务-实现vsftpd虚拟用户
前几篇介绍了基础,这篇将具体实现几个案例 实现基于文件验证的vsftpd虚拟用户,每个用户独立一个文件夹 1.创建用户数据库文件 vim /etc/vsftpd/vusers.txt qq cento ...
- 如何用纯 CSS 创作一台拍立得照相机
效果预览 按下右侧的"点击预览"按钮可以在当前页面预览,点击链接可以全屏预览. https://codepen.io/comehope/pen/YjYgey 可交互视频 此视频是可 ...
- OwinStartupAttribute出错
尝试加载应用时出现了以下错误.- 找不到包含 OwinStartupAttribute 的程序集.- 找不到包含 Startup 或 [AssemblyName].Startup 类的程序集.若要禁用 ...