题目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多线程——Lock&Condition
Lock比传统线程模型中的synchronized方式更加面向对象,与生活中的锁类似,锁本身也应该是一个对象.两个线程执行的代码片段要实现同步互斥的效果,它们必须用同一个Lock对象. package ...
- 第一篇 一步一步看透C++
毕业快一年半了,这些时候,都是在底层方面做的一些工作,虽然内核的C也实现了C++中的一些抽象机制,面向对象,继承,多态,封装等等,但是,想着大学里面,电子类的学习,都是偏向底层的,有过C++的 ...
- ASP.net在网页上显示当前时间,利用AJAX不刷新网页
前台页面代码: <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default. ...
- 调整iRedmail之Roundcube webmail服务不可不知的几件事
iRedMail集成了roundcube webmail,极大的方便了安装维护工作,但是需求是千遍万化的,总有需要深入调整的地方.下面就是我调整roundcube时遇到的几点问题: 一.修改网页标题p ...
- JUnit 3一个例子就懂
JUnit is a simple framework to write repeatable tests. It is an instance of the xUnit architecture f ...
- UNIX环境编程学习笔记(1):——出错处理errno
lienhua342014 年 8 月 24 日 1. errno变量 文件 <errno.h> 中定义了符号 errno 以及可以赋予它的各种常量,这些常量都是以字符 E 开头.例如,若 ...
- C#特性文章学习
http://www.cnblogs.com/rohelm/archive/2012/04/19/2456088.html http://www.cnblogs.com/liuxinxin/artic ...
- python 数据类型-字符串-对象和方法
python的字符串有众多方法,可以在doc文档中查看 示例 转换开头字母为大写 c1="welcome to my python" >>> c1.capital ...
- NHibernate 集合映射深入 (第五篇) <set>,<list>,<map>,<bag>
一.集合外键 在NHibernate中,典型的用于映射集合类的元素有<set>,<list>,<map>,<bag>,<array>,< ...
- IOS 应用官方接口地址
地址: http://www.apple.com/itunes/affiliates/resources/documentation/itunes-store-web-service-search-a ...