题目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 问题描述 这道题理解题意有些麻烦,多看几遍先理解题意再说.每个学生有自己的三个成绩,一个编号,以及一个志愿列 ...
随机推荐
- linux下时间同步的两种方法分享
方法1:与一个已知的时间服务器同步 复制代码 代码如下: ntpdate time.nist.gov 其中 time.nist.gov 是一个时间服务器. 删除本地时间并设置时区为上海 复制代码 代码 ...
- 限定某个目录禁止解析php 限制user_agent php相关配置
- 两个大数组foreach,找出相同的key数量,所用的时间对比
<?php function microtime_float() { list($usec, $sec) = explode(" ", microtime()); retur ...
- __setup、early_param的解析
内核初始化时根据字符串匹配获得相应的处理函数,查找的时候有些麻烦. 写个脚本对将内核中的__setup和early_param显式做了解析: __setup #! /bin/bash grep '\& ...
- Greenplum-cc-web监控软件安装时常见错误
错误error: 1.no pg_hba.conf entry for host “::1”, user “gpmon”, database “gpperfmon”, SSL off 解决: vi ...
- virtualbox谨记:续....
接“virtualbox谨记:win7上只有4.3.x的版本支持ubuntu14.04.3虚拟机安装Oracle Rac,其他的版本3.x和5.0.2(至2015-08-30)均不可以”, 续 me自 ...
- mysql 错误代码:1118解决方法
错误描述: 错误代码: 1118Row size too large. The maximum row size for the used table type, not counting BLOBs ...
- easyui分页,编辑datagrid某条数据保存以后跳转到某一页
参考资料:http://caizhilin2010.iteye.com/blog/1731698 问题:商品列表页面采用easyui的datagrid展示数据,编辑某行数据保存以后,要求跳转到 用户在 ...
- 苹果官方xcodeprojectbuild设置指南
https://developer.apple.com/library/ios/documentation/DeveloperTools/Reference/XcodeBuildSettingRef/ ...
- JAVA简单内存泄露分析及解决
一.问题产生 项目采用Tomcat6.0为服务器,数据库为mysql5.1,数据库持久层为hibernate3.0,以springMVC3.0为框架,项目开发完成后,上线前夕进行稳定性拷机,测试 ...