九度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;
}

你可能感兴趣的:(九度OJ 1005)