题目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>
#include <vector>
#include <algorithm>
using namespace std;

int n,m,k;
typedef struct Student{
    int id;
    int GE;
    int GI;
    double Final;
    int choice[6];
}Student;
typedef struct School{
    int now;//已招人数
    int Max;//最大人数
    vector<int> admit;
}School;

Student Stu[40005];
School Sch[105];

bool cmp(Student a,Student b)
{
    if(a.Final!=b.Final) return a.Final>b.Final;
    else return a.GE>b.GE;
}

int main()
{
    while(~scanf("%d%d%d",&n,&m,&k))
    {
        for(int i=0;i<m;i++)
        {
            scanf("%d",&Sch[i].Max);
            Sch[i].now=0;
            Sch[i].admit.clear();
        }

        for(int i=0;i<n;i++)
        {
            Stu[i].id=i;
            scanf("%d %d",&Stu[i].GE,&Stu[i].GI);
            Stu[i].Final=(Stu[i].GE+Stu[i].GI)/2;
            for(int j=0;j<k;j++)
                scanf("%d",&Stu[i].choice[j]);
        }
        sort(Stu,Stu+n,cmp);

        for(int i=0;i<n;i++)
        {
            for(int j=0;j<k;j++)
            {
                int quota=Stu[i].choice[j];
                if(Sch[quota].now==0&&Sch[quota].Max==0) break;
                else if(Sch[quota].now<Sch[quota].Max)
                {
                    Sch[quota].now++;
                    Sch[quota].admit.push_back(i);
                    break;//已录取,退出
                }
                else
                {
                    int lastone=Sch[quota].admit[Sch[quota].now-1];
                    if(Stu[lastone].GE==Stu[i].GE&&Stu[lastone].GI==Stu[i].GI)
                    {
                        Sch[quota].now++;
                        Sch[quota].admit.push_back(i);
                        break;//已录取,退出
                    }
                }
            }
        }

        for(int i=0;i<m;i++)//实际ID还原
            for(int j=0;j<Sch[i].now;j++)
                Sch[i].admit[j]=Stu[Sch[i].admit[j]].id;

        for(int i=0;i<m;i++)
        {
            if(Sch[i].now==0) printf("\n");
            else if(Sch[i].now==1) printf("%d\n",Sch[i].admit[0]);
            else
            {
                sort(Sch[i].admit.begin(),Sch[i].admit.end());
                int flag = 1;
                for(int j=0;j<Sch[i].now;j++)
                {
                    if(flag) flag=0;
                    else printf(" ");

                    printf("%d",Sch[i].admit[j]);
                }
                printf("\n");
            }
        }
    }
}
时间: 2024-10-06 22:28:50

题目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

题目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. // #

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

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

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

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

1080. Graduate Admission (30) (模拟排序啊 ZJU_PAT)

题目链接:http://www.patest.cn/contests/pat-a-practise/1080 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 adm

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