题目链接: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(录取算法)的更多相关文章

  1. 题目1005:Graduate Admission

    题目1005:Graduate Admission 时间限制:1 秒 内存限制:32 兆 特殊判题:否 题目描述: It is said that in 2011, there are about 1 ...

  2. PAT 1080 Graduate Admission[排序][难]

    1080 Graduate Admission(30 分) It is said that in 2011, there are about 100 graduate schools ready to ...

  3. PAT_A1080#Graduate Admission

    Source: PAT A1080 Graduate Admission (30 分) Description: It is said that in 2011, there are about 10 ...

  4. PAT-1080 Graduate Admission (结构体排序)

    1080. Graduate Admission It is said that in 2013, there were about 100 graduate schools ready to pro ...

  5. 1080 Graduate Admission——PAT甲级真题

    1080 Graduate Admission--PAT甲级练习题 It is said that in 2013, there were about 100 graduate schools rea ...

  6. pat 甲级 1080. Graduate Admission (30)

    1080. Graduate Admission (30) 时间限制 200 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue It ...

  7. PAT 甲级 1080 Graduate Admission (30 分) (简单,结构体排序模拟)

    1080 Graduate Admission (30 分)   It is said that in 2011, there are about 100 graduate schools ready ...

  8. pat1080. Graduate Admission (30)

    1080. Graduate Admission (30) 时间限制 200 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue It ...

  9. 题目1005:Graduate Admission(结构体排序)

    问题来源 http://ac.jobdu.com/problem.php?pid=1005 问题描述 这道题理解题意有些麻烦,多看几遍先理解题意再说.每个学生有自己的三个成绩,一个编号,以及一个志愿列 ...

随机推荐

  1. 使用redis镜像

    运行容器 runoob@runoob:~/redis$ docker run -p : -v $PWD/data:/data -d redis:3.2 redis-server --appendonl ...

  2. Objective-C 语法之 Debug 表达式

    main.m #import <Foundation/Foundation.h> #import "TestClass.h" int main(int argc, co ...

  3. git远端删除被提交后又被加到.gitignore的文件

    远端删除文件而不影响本地文件 git rm [-r] --cached file_or_dir_name 利用.gitignore来自动删除所有匹配文件 我试过网上推荐的写法 git rm --cac ...

  4. Linux安装rpc监控系统资源

    1.rpc服务需rsh的支持,一般情况下rsh已安装.rpm -qa rsh查看. 2.右键另存为http://heanet.dl.sourceforge.net/sourceforge/rstatd ...

  5. sql产生随机时间

    --建立过程 CREATE PROCEDURE GetTime     @BeginTime VARCHAR(5),     @EndTime VARCHAR(5),     @RandTime VA ...

  6. CorelDRAW中关于锁定与解锁对象的操作

    在编辑复制的图形时,有时为了避免对象受到操作的影响,可以使用“锁定与解锁对象”功能键对已经编辑好的对象进行锁定.被锁定的对象将不能进行任何编辑操作,本教程将详解CorelDRAW中关于锁定与解锁对象的 ...

  7. yum和apt-get用法及区别

    https://www.cnblogs.com/garinzhang/p/diff_between_yum_apt-get_in_linux.html

  8. C# AES要解密的数据的长度无效

    加密方式  AES-CBC-128 将解密方法改成如下 public string Decrypt(string toDecrypt, string key) { if (string.IsNullO ...

  9. IOS UILineBreakMode的各种情况分析

    typedef enum {    UILineBreakModeWordWrap = 0,    UILineBreakModeCharacterWrap,    UILineBreakModeCl ...

  10. Java利用while循环计算1+1/2!+1/3!……+1/20!

    编写程序,用while语句计算1+1/2!+1/3!……+1/20!,并在控制泰山输出计算结果.要求1+1/2!+1/3!……+1/20!,其实就是求1+1*1/2+1*1/2*1/3+……+1*1/ ...