题目1005:Graduate Admission(录取算法)
题目链接:http://ac.jobdu.com/problem.php?pid=1005
详解链接:https://github.com/zpfbuaa/JobduInCPlusPlus
参考代码:
//
// 1005 Graduate Admission.cpp
// Jobdu
//
// Created by PengFei_Zheng on 27/04/2017.
// Copyright © 2017 PengFei_Zheng. All rights reserved.
// #include <stdio.h>
#include <iostream>
#include <algorithm>
#include <string.h>
#include <cmath>
#define CHOOSE 6
#define MAX_SIZE 40001
#define SCHOOL 101 using namespace std; int n, m, k ; struct Apply{
int ge;
int gi;
double gf;
int choose[CHOOSE];
int id;
bool operator < (const Apply &A) const{
if(gf != A.gf){
return gf > A.gf;
}
else if(ge != A.ge){
return ge > A.ge;
}
else {
return ge > A.ge;
}
}
};
struct School{
int quota;
int realNum;
int appid[MAX_SIZE];
}; Apply apply[MAX_SIZE];
School school[SCHOOL]; int main(){
while(scanf("%d%d%d",&n,&m,&k)!=EOF){ for(int i = ; i < m ; i++){
scanf("%d",&school[i].quota);
school[i].realNum=;
}
for(int i = ; i < n ; i++){
scanf("%d%d",&apply[i].ge,&apply[i].gi); apply[i].gf=(double)(apply[i].ge+apply[i].gi)/2.0; for(int j = ; j < k ; j++){
scanf("%d",&apply[i].choose[j]);
}
apply[i].id=i;
}
sort(apply,apply+n);
int sid;
for(int i = ; i < n ; i++){
for(int j = ; j < k ; j++){
sid = apply[i].choose[j];
if(school[sid].quota > ){
school[sid].appid[school[sid].realNum] = i;
school[sid].realNum++;
school[sid].quota--;
break;
}
else{
int lastid = school[sid].appid[school[sid].realNum-];
if(apply[i].gf == apply[lastid].gf && apply[i].ge == apply[lastid].ge){
school[sid].appid[school[sid].realNum]=i;
school[sid].realNum++;
school[sid].quota--;
break;
}
}
}
} for(int i = ; i < m ; i++){
for(int j = ; j < school[i].realNum ; j++){
school[i].appid[j] = apply[school[i].appid[j]].id;
}
} for(int i = ; i < m ; i++){
if(school[i].realNum==){
printf("\n");
}
else if(school[i].realNum==){
printf("%d\n",school[i].appid[]);
}
else{
sort(school[i].appid,school[i].appid+school[i].realNum);
bool first = true;
for(int j = ; j < school[i].realNum ; j++){
if(first==true){
first = false;
}
else{
printf(" ");
}
printf("%d",school[i].appid[j]);
}
printf("\n");
}
}
}
return ;
}
/**************************************************************
Problem: 1005
User: zpfbuaa
Language: C++
Result: Accepted
Time:0 ms
Memory:19180 kb
****************************************************************/
题目1005:Graduate Admission(录取算法)的更多相关文章
- 题目1005:Graduate Admission
题目1005:Graduate Admission 时间限制:1 秒 内存限制:32 兆 特殊判题:否 题目描述: It is said that in 2011, there are about 1 ...
- PAT 1080 Graduate Admission[排序][难]
1080 Graduate Admission(30 分) It is said that in 2011, there are about 100 graduate schools ready to ...
- PAT_A1080#Graduate Admission
Source: PAT A1080 Graduate Admission (30 分) Description: It is said that in 2011, there are about 10 ...
- PAT-1080 Graduate Admission (结构体排序)
1080. Graduate Admission It is said that in 2013, there were about 100 graduate schools ready to pro ...
- 1080 Graduate Admission——PAT甲级真题
1080 Graduate Admission--PAT甲级练习题 It is said that in 2013, there were about 100 graduate schools rea ...
- pat 甲级 1080. Graduate Admission (30)
1080. Graduate Admission (30) 时间限制 200 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue It ...
- PAT 甲级 1080 Graduate Admission (30 分) (简单,结构体排序模拟)
1080 Graduate Admission (30 分) It is said that in 2011, there are about 100 graduate schools ready ...
- pat1080. Graduate Admission (30)
1080. Graduate Admission (30) 时间限制 200 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue It ...
- 题目1005:Graduate Admission(结构体排序)
问题来源 http://ac.jobdu.com/problem.php?pid=1005 问题描述 这道题理解题意有些麻烦,多看几遍先理解题意再说.每个学生有自己的三个成绩,一个编号,以及一个志愿列 ...
随机推荐
- Java开发者必备的六款工具
每一位Java程序员都会有套工具来应对工作上的挑战.多年来,Java程序员使用软件来完成他们的工作.有很多工具对他们是有用的,不过对于初入行的人员来说,寻找合适的工具是困难的,并且是浪费时间的.而今天 ...
- Yii2 session的使用方法(1)
yii2打开session use yii\web\Session; $session = Yii::$app->session; // check if a session is alread ...
- Memcached Java Client比较
JAVA客户端调用memcached比较 Memcached 客户端程序三种API的比较 Java开发中的Memcache原理及实现(五)Memcached客户端
- iptables filter表小案例
案例1:把80端口,22端口,21端口放行 22端口指定IP访问,其它IP拒绝. shell脚本实现: [root@centos7 ~]# vim /usr/local/sbin/iptables.s ...
- linux下命令行打开文件管理器
nautilus,这个太有用了,应为可以在secureCRT中使用,因为可以添加sudo来调用
- Android开发中常用的库总结(持续更新)
这篇文章用来收集Android开发中常用的库,都是实际使用过的.持续更新... 1.消息提示的小红点 微信,微博消息提示的小红点. 开源库地址:https://github.com/stefanjau ...
- eclipse 运行springboot项目
一:当在eclipse启动spring boot项目时出现问题: 错误: 找不到或无法加载主类 com.example.demo.DemoApplication 解决办法: 1,通过cmd命令行,进入 ...
- springmvc+freemarker生成静态html文件
参考资料: http://mylfd.iteye.com/blog/1896501 http://www.cnblogs.com/xxt19970908/p/5553045.html 个人实践: 1. ...
- mysql覆盖索引(屌的狠,提高速度)
话说有这么一个表: CREATE TABLE `user_group` ( `id` int(11) NOT NULL auto_increment, `uid` int(11) NOT NULL, ...
- HTML5媒体(音频/视频)
摘要: 在HTML5出现之前,web媒体大部分通过Flash来实现.这种方式造成了文件大加载慢,影响网站性能,开发难度高,维护麻烦,不易扩展等.这就导致HTML5自己开始支持媒体功能.HTML5 DO ...