题目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 = 0 ; i < m ; i++){
            scanf("%d",&school[i].quota);
            school[i].realNum=0;
        }
        for(int i = 0 ; 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 = 0 ; j < k ; j++){
                scanf("%d",&apply[i].choose[j]);
            }
            apply[i].id=i;
        }
        sort(apply,apply+n);
        int sid;
        for(int i = 0 ; i < n ; i++){
            for(int j = 0 ; j < k ; j++){
                sid = apply[i].choose[j];
                if(school[sid].quota > 0){
                    school[sid].appid[school[sid].realNum] = i;
                    school[sid].realNum++;
                    school[sid].quota--;
                    break;
                }
                else{
                    int lastid = school[sid].appid[school[sid].realNum-1];
                    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 = 0 ; i < m ; i++){
            for(int j = 0 ; j < school[i].realNum ; j++){
                school[i].appid[j] = apply[school[i].appid[j]].id;
            }
        }

        for(int i = 0 ; i < m ; i++){
            if(school[i].realNum==0){
                printf("\n");
            }
            else if(school[i].realNum==1){
                printf("%d\n",school[i].appid[0]);
            }
            else{
                sort(school[i].appid,school[i].appid+school[i].realNum);
                bool first = true;
                for(int j = 0 ; j < school[i].realNum ; j++){
                    if(first==true){
                        first = false;
                    }
                    else{
                        printf(" ");
                    }
                    printf("%d",school[i].appid[j]);
                }
                printf("\n");
            }
        }
    }
    return 0;
}
/**************************************************************
    Problem: 1005
    User: zpfbuaa
    Language: C++
    Result: Accepted
    Time:0 ms
    Memory:19180 kb
****************************************************************/
时间: 2024-10-23 06:56:15

题目1005:Graduate Admission(录取算法)的相关文章

1005.Graduate Admission

题目描述: It is said that in 2011, there are about 100 graduate schools ready to proceed over 40,000 applications in Zhejiang Province. It would help a lot if you could write a program to automate the admission procedure. Each applicant will have to prov

PAT A1080 Graduate Admission

PAT A1080 Graduate Admission 题目描述: It is said that in 2011, there are about 100 graduate schools ready to proceed over 40,000 applications in Zhejiang Province. It would help a lot if you could write a program to automate the admission procedure. Eac

1080. Graduate Admission (30)

1080. Graduate Admission (30) 时间限制 200 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue It is said that in 2013, there were about 100 graduate schools ready to proceed over 40,000 applications in Zhejiang Province. It would help a lot if yo

PAT 1080. Graduate Admission (30)

1080. Graduate Admission (30) It is said that in 2013, there were about 100 graduate schools ready to proceed over 40,000 applications in Zhejiang Province. It would help a lot if you could write a program to automate the admission procedure. Each ap

pat1080. Graduate Admission (30)

1080. Graduate Admission (30) 时间限制 200 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue It is said that in 2013, there were about 100 graduate schools ready to proceed over 40,000 applications in Zhejiang Province. It would help a lot if yo

题目1005:Graduate Admission

题目链接:http://ac.jobdu.com/problem.php?pid=1005 详解连接:https://github.com/Pacsiy/JobDu 参考代码: // // Created by AlvinZH on 2017/4/27. // Copyright (c) AlvinZH. All rights reserved. // #include <iostream> #include <cstdio> #include <cmath> #inc

PAT:1080. Graduate Admission (30) 部分错误(录取以学校为导向而不是考生志愿为导向导致的错误)

#include<stdio.h> #include<string.h> #include<algorithm> using namespace std; int want[106]; //各学校招生人数 struct Student { int GE,GI,sum,rank,ID; int prefer[6]; bool R; //代表该生录取情况 }STU[40066]; bool cmp(Student a,Student b) { if(a.sum!=b.sum

2011年浙大:Graduate Admission

题目描述: It is said that in 2011, there are about 100 graduate schools ready to proceed over 40,000 applications in Zhejiang Province. It would help a lot if you could write a program to automate the admission procedure.    Each applicant will have to p

PAT(A) 1080. Graduate Admission (30)

It is said that in 2013, there were about 100 graduate schools ready to proceed over 40,000 applications in Zhejiang Province. It would help a lot if you could write a program to automate the admission procedure. Each applicant will have to provide t