online_judge_1005

183 篇文章 0 订阅
#include <iostream>
#include <algorithm>

using namespace std;

struct Student
{
    int school[101];
    int GE,GI,GS;
    int id;
    bool operator < (const Student &A) const
    {
        return !(GS<A.GS || (GS==A.GS && (GE<A.GE)));
    }
    bool operator == (const Student &A) const
    {
        if(GE == A.GE && GI == A.GI)
        {
            for(int i=0; i<101; ++i)
            {
                if(school[i] != A.school[i])
                    return false;
            }
            return true;
        }
        return false;
    }
}stu[40001];

struct Result
{
    int schoolID;
    int studentID;
    bool operator < (const Result &A) const
    {
        return (schoolID < A.schoolID || (schoolID == A.schoolID && studentID < A.studentID));
    }
}result[40001];

int main()
{
    int n,m,k;
    int i,j,t,h;
    int a[101];
    while(cin>>n>>m>>k)
    {
        for(i=0; i<m; ++i)
            cin>>a[i];
        for(i=0; i<n; ++i)
        {
            cin>>stu[i].GE>>stu[i].GI;
            stu[i].id = i;
            stu[i].GS = stu[i].GE + stu[i].GI;
            for(j=0; j<101; ++j)
                stu[i].school[j] = -1;
            for(j=0; j<k; ++j)
                cin>>stu[i].school[j];
        }
        sort(stu, stu+n);
        h = 0;
        for(i=0; i<n; ++i)
        {
            for(j=0; j<k; ++j)
            {
                t = stu[i].school[j];
                if(a[t] > 0)
                {
                    a[t]--;
                    result[h].schoolID = t;
                    result[h].studentID = stu[i].id;
                    ++h;
                    break;
                }
                else if(a[t] == 0)
                {
                    //int s = result[h-1].studentID;
                    if(i == 0)
                        break;
                    if(stu[i-1] == stu[i])
                    {
                        result[h].schoolID = result[h-1].schoolID;
                        result[h].studentID = stu[i].id;
                        ++h;
                        break;
                    }
                }
            }
        }
        sort(result, result+h);
        t = 0;
        int flag;
        for(i=0; i<m; ++i)
        {
            flag = 0;
            while(t<h && result[t].schoolID == i)
            {
                if(flag++ == 0)
                {
                    cout<<result[t].studentID;
                }
                else
                    cout<<" "<<result[t].studentID;
                t++;
            }
            cout<<endl;
        }
    }
    return 0;
}


花了一个半小时才做出来这题,真是太激动了。这个题目以前就不会做。。这次一次通过,很激动……虽然代码写的很乱,但是我的思维还是比较清晰的。。

很多时候真是缺乏锻炼,总是想的多,做得少,这是病,得治。。继续努力。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值