Flo's Restaurant

Flo's Restaurant

Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other)
Total Submission(s) : 5   Accepted Submission(s) : 2
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
 

今天感觉累了,写篇博客放松一下。
这道题汉语意思就是在一个饭馆,有三种类型一个人和两个人吃饭坐二人桌,三个四个人坐四人桌,五六个人坐六人桌。假设每桌人吃饭花半个小时,来的人最多也是等半个小时,看每天可以有多少个人在这吃饭。

处理这个题我们可以先让人坐,把位子坐满,然后我们把位子上的人进行排序,先吃完的最早等的人坐。然后再进行排序,排序我们可以用一个队列,队列有先进先出的原则,所以处理的很方便。

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<set>
#include<cstring>
#include<queue>
using namespace std;
int main()
{
    int a,b,c,sum,m,x,y,h,p;
    char st[100];
    queue<int>q1,q2,q3;
    while(~scanf("%d%d%d",&a,&b,&c))
    {
        sum=0;
        if(a==0&&b==0&&c==0)break;
        while(!q1.empty())//清空队列里的元素。
        {
            q1.pop();
        }
        while(!q2.empty())
        {
            q2.pop();
        }
        while(!q3.empty())
        {
            q3.pop();
        }
        while(scanf("%s",st))
        {
            if(st[0]=='#')break;
            sscanf(st,"%d:%d",&x,&y);//字符串和数组的转换我写过一篇博客点击打开链接
            scanf("%d",&m);
            h=x*60+y;
            if(m<=2)
            {
                if(a>0)//让来的人先坐。
                {
                    q1.push(h+30);
                    sum+=m;
                    a--;
                }
                else//坐满之后然后看是否等的不超过半个小时,如果可以吃上饭,就进入队列,最前面的出队列。
                {
                    p=q1.front();
                    if(h+30>=p)
                    {
                        q1.pop();
                        q1.push(max(h+30,p+30));//这里是一个关键,因为有可能来的早的已经走了,或者还有不到半个小时就吃完了,我们要选时间大的输入。
                        sum+=m;
                    }
                }
            }
            else if(m<=4&&m>2)
            {
                if(b>0)
                {
                    q2.push(h+30);
                    sum+=m;
                    b--;
                }
                else
                {
                    p=q2.front();
                    if(h+30>=p)
                    {
                        q2.pop();
                        q2.push(max(h+30,p+30));
                        sum+=m;
                    }
                }
            }
            else if(m>4&&m<=6)
            {
                if(c>0)
                {
                    q3.push(h+30);
                    sum+=m;
                    c--;
                }
                else
                {
                    p=q3.front();
                    if(h+30>=p)
                    {
                        q3.pop();
                        q3.push(max(h+30,p+30));
                        sum+=m;
                    }
                }
            }
        }printf("%d\n",sum);
    }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值