HDU 1103 Restaurant

Flo's Restaurant

                                                                    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
                                                                                                       Total Submission(s): 1463    Accepted Submission(s): 440


Problem Description
Sick and tired of pushing paper in the dreary bleary-eyed world of finance, Flo ditched her desk job and built her own restaurant.

In the small restaurant, there are several two-seat tables, four-seat tables and six-seat tables. A single diner or a group of two diners should be arranged to a two-seat table, a group of three or four diners should be arranged to a four-seat table, and a group of five or six diners should be arranged to a six-seat table.

Flo’s restaurant serves delicious food, and many people like to eat here. Every day when lunch time comes, the restaurant is usually full of diners. If there is no suitable table for a new coming group of diners, they have to wait until some suitable table is free and there isn’t an earlier arrival group waiting for the same kind of tables. Kind Flo will tell them how long they will get their seat, and if it’s longer than half an hour, they will leave for another restaurant.

Now given the list of coming diners in a day, please calculate how many diners take their food in Flo’s restaurant. You may assume it takes half an hour for every diner from taking a seat to leaving the restaurant.
 

Input
There are several test cases. The first line of each case contains there positive integers separated by blanks, A, B and C (A, B, C >0, A + B + C <= 100), which are the number of two-seat tables, the number of four-seat tables and the number of six-seat tables respectively. From the second line, there is a list of coming groups of diners, each line of which contains two integers, T and N (0 < N <= 6), representing the arrival time and the number of diners of each group. The arrival time T is denoted by HH:MM, and fixed between 08:00 and 22:00 (the restaurant closes at 23:00). The list is sorted by the arrival time of each group in an ascending order, and you may assume that no groups arrive at the same time. Each test case is ended by a line of “#”.

A test case with A = B = C = 0 ends the input, and should not be processed.
 

Output
For each test case, you should output an integer, the total number of diners who take their food in Flo’s restaurant, in a separated line.
 

Sample Input
  
  
1 1 1 10:40 1 10:50 2 11:00 4 # 1 1 1 10:40 1 10:50 2 11:00 2 # 1 2 1 10:30 1 10:40 3 10:50 2 11:00 1 11:20 5 # 0 0 0
 

Sample Output
  
  
7 3 12
 

Author
Alcyone
 

Recommend
Eddy   |   We have carefully selected several similar problems for you:   1119  1110  1107  1104  1117 
 

题目链接http://acm.hdu.edu.cn/showproblem.php?pid=1103


分析:

优先队列Table[ i ] ,下标表示桌子类型编号1、2、3,优先队列里保存同类型所有桌子上的

客人用餐结束时间(越小越优先)

每当有顾客来的时候,判断是否有桌子可以坐下来,并更新队列


代码:

#include <cstdio>
#include <queue>
#include <functional>
using namespace std;
//3种桌子分别用下标为1、2、3的优先队列表示
priority_queue<int, vector<int>, greater<int> > Table[5];

int main()
{
    int a, b, c;
    while (~scanf("%d%d%d", &a, &b, &c))
    {
        if (a + b + c == 0)
            break;
        for (int i = 1; i <= 3; i++)
        {
            while (!Table[i].empty())
                Table[i].pop();
        }

        for (int i = 1; i <= a; i++)    //将每种桌子加入队列
            Table[1].push(0);
        for (int i = 1; i <= b; i++)
            Table[2].push(0);
        for (int i = 1; i <= c; i++)
            Table[3].push(0);

        char Time[10];
        int num, cnt = 0;
        while (1)
        {
            scanf("%s", Time);
            if (Time[0] == '#')
                break;
            scanf("%d", &num);
            int hh = 10 * (Time[0] - '0') + Time[1] - '0';
            int mm = 10 * (Time[3] - '0') + Time[4] - '0';
            int Merge = hh * 60 + mm;       //将时间转换为分钟表示
            int index = (num + 1)/ 2;       //由顾客数目得到桌子种类的编号
            if (Merge + 30 >= Table[index].top())       //判断是否能坐下吃美味
            {
                cnt += num;
                //此处注意,求当前顾客的开始吃饭时间,
                //应为上一波顾客的结束时间与当前顾客的开始时间中的较大者
                int Max = max(Table[index].top(), Merge);
                Table[index].push(Max + 30);        //将当前顾客的结束时间加入队列
                Table[index].pop();
            }
        }
        printf("%d\n", cnt);
    }
    return 0;
}




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值