hdu1871无题

#include <iostream>
#include <algorithm>
using namespace std;
struct hotel{
    int num;
    int room_num;
    int price;
};
bool cmp(hotel a,hotel b)    //先按价格升序,再按房间数升序,最后按编号
{
    if(a.price != b.price)
    return a.price < b.price;
    else if(a.room_num != b.room_num)
    return a.price < b.price;
    else
    return a.num < b.num;
}
int main()
{
    hotel a[200];
    int t,c,i,T,n,ok;
    cin >> T;
    while(T--)
    {
        cin >> c;
        for(i = 0; i < c; ++i)
        cin >> a[i].num >> a[i].room_num >> a[i].price;
        sort(a,a+c,cmp);
        cin >> t;
        while(t--)
        {
            cin >> n;
            for(i = 0; i < c; ++i)
            {
                if(a[i].room_num >= n)
                {
                    a[i].room_num -= n;         //被住进后空房数减n
                    cout << a[i].num << endl;
                    ok = 1;
                    break;
                }
                if(i == c - 1)
                cout << "sorry" << endl;
            }
        }
    }
    return 0;
}
原文地址:https://www.cnblogs.com/fchx/p/2880491.html