题目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 问题描述 这道题理解题意有些麻烦,多看几遍先理解题意再说.每个学生有自己的三个成绩,一个编号,以及一个志愿列 ...
随机推荐
- c#中//注释和///注释的区别 智能注释 显示换行
///会被编译,//不会所以使用///会减慢编译的速度(但不会影响执行速度)///会在其它的人调用你的代码时提供智能感知 也是一种注释,但是这种注释主要有两种作用:1.这些注释能够生成一个XML文件. ...
- Win7-64位安装TensorFlow-GPU
1.查看电脑显卡 路径:计算机--属性--设备管理器-显示适配器 2.显卡(GPU)是否支持CUDN https://developer.nvidia.com/cuda-gpus 3.安装 1)CUD ...
- 8.1 shell介绍 8.2 命令历史 8.3 命令补全和别名 8.4 通配符 8.5 输入输出重定向
8.1 shell介绍 8.2 命令历史 8.3 命令补全和别名 8.4 通配符 8.5 输入输出重定向 什么是shell? shell是一个命令解释器,提供用户和及其之间的交互 致辞特定语法,比如逻 ...
- OpenGL核心技术之帧缓冲
笔者介绍:姜雪伟.IT公司技术合伙人,IT高级讲师.CSDN社区专家.特邀编辑.畅销书作者,国家专利发明人;已出版书籍:<手把手教你架构3D游戏引擎>电子工业出版社和<Unity3D ...
- 【python-proxy by sockets5】pysocks
pip install pysocks https://stackoverflow.com/questions/2317849/how-can-i-use-a-socks-4-5-proxy-with ...
- perforce变量配置与使用
linux Perforce 使用 1.配置环境变量: 下载 perforce 放到/usr/bin/下 export P4PORT=192.168.4.88:1666 #P4所在的主机exp ...
- QT 随机数生成
下面总结了QT中随机生成的方法(仅供学习参考),分为旧方法和新方法,一般来说,旧的方法已经被抛弃,在开发新的应用中推荐使用新方法. C++ Code 12345678910111213141516 ...
- VS或编译的时候不生成Release文件夹
今天在编译第三方类的时候,总是发布的时候报没有第三方类库的的Release版本 解决方案: Build=>Configuration Manager=>Release 编译=>配置管 ...
- mysql中date_add()函数的使用?
需求描述: 在使用mysql的过程中,需要对日期进行计算,比如对某个日期加上几天,几个小时等操作, 在此记录下,date_add()函数的使用. 操作过程: date_add()函数语法: DATE_ ...
- Go工具和调试详解
https://blog.csdn.net/happyanger6/article/details/78724594/ https://blog.csdn.net/u012210379/article ...