九度OJ 1005

#include <iostream>
#include <queue>
#include <algorithm>
#include <iterator>
using namespace std;

class student
{
public:
    student(int rk, int i, int j) : ge(rk), gi(i), id(j){}
    int getRank(){return ge + gi;}
    int getGe(){return ge;}
    int getGi(){return gi;}
    int getSch(){return q.front();}
    int getId(){return id;}
    bool isEmpty(){return q.empty();}
    void popSch(){q.pop();}
    void pushSch(int sch){q.push(sch);}

private:
    int id;
    int ge;
    int gi;
    queue<int> q;
};

bool cmp (student *a, student *b)
{
    if(a->getRank() > b->getRank())
        return true;
    else if(a->getRank() == b->getRank() && a->getId() < b->getId())
        return true;
    else
        return false;
}

class school
{
public:
    void setId(int i){id = i;}
    int getId(){return id;}
    bool isFull(){return stuId.size() >= maxNum;}
    int getMaxNum(){return maxNum;}
    void setMaxNum(int t){maxNum = t;}
    void insertStu(int id, int i, int j)
    {
        stuId.push_back(id);
        ge.push_back(i);
        gi.push_back(j);
    }
    void show()
    {
        sort(stuId.begin(), stuId.end());
        //copy(stuId.begin(), stuId.end(), ostream_iterator<int>(cout, " "));
        if(!stuId.empty())
            cout << stuId[0];
        for(int i = 1; i < stuId.size(); ++i)
        {
 cout << " " << stuId[i];
        }
        cout << endl;
    }

    int getGe(){return ge.back();}
    int getGi(){return gi.back();}
private:
    vector<int> stuId;
    vector<int> ge;
    vector<int> gi;
    int maxNum;
    int id;
};

int main()
{
    int n, m, k;
    vector<student*> vecStu;
    vector<school*> vecSch;
    while(cin >> n >> m >> k)
    {
        for(int i = 0; i < m; ++i)
        {
            int temp;
            cin >> temp;
            school *sch = new school;
            sch->setMaxNum(temp);
            sch->setId(i);
            vecSch.push_back(sch);
        }
        for(int i = 0; i < n; ++i)
        {
            int ge, gi, schId;
            cin >> ge >> gi;
            student *stu = new student(ge, gi, i);
            for(int j = 0; j < k; ++j)
            {
                cin >> schId;
                stu->pushSch(schId);
            }
            vecStu.push_back(stu);
        }
 sort(vecStu.begin(), vecStu.end(), cmp);
        for(int i = 0; i < n; ++i)
        {
            while(!vecStu[i]->isEmpty())
            {
                if(vecSch[vecStu[i]->getSch()]->isFull())
                {
                    if(vecStu[i]->getGe() == vecSch[vecStu[i]->getSch()]->getGe() && vecStu[i]->getGi() == vecSch[vecStu[i]->getSch()]->getGi())
                    {
                        vecSch[vecStu[i]->getSch()]->insertStu(vecStu[i]->getId(), vecStu[i]->getGe(), vecStu[i]->getGi());
                        break;
                    }
                    else
                    {
                        vecStu[i]->popSch();
                    }
                }
                else
                {
                    vecSch[vecStu[i]->getSch()]->insertStu(vecStu[i]->getId(), vecStu[i]->getGe(), vecStu[i]->getGi());
                    break;
                }
            }
        }
        for(int i = 0; i < m; ++i)
        {
            vecSch[i]->show();
        }
        for(int i = 0; i < m; ++i)
        {
            delete vecSch[i];
        }
        for(int i = 0; i < n; ++i)
        {
            delete vecStu[i];
        }
        vecStu.clear();
        vecSch.clear();
    }
    return 0;
}

转载于:https://my.oschina.net/u/196018/blog/383805

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值