zoukankan      html  css  js  c++  java
  • 杭电 1103 Flo's Restaurant

    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<queue>
    #include<algorithm>
    #include<vector>
    #include<functional>
    using namespace std;
    int max(int a,int b)
    {
        return a>b?a:b;
    }
    int main()
    {
        int a,b,c,t[3],h,m,e,d,n;
        int  i;
        priority_queue<int,vector<int>,greater<int> > as[3];
        char s[7];
        while(scanf("%d%d%d",&a,&b,&c)==3&&a)
        {
            for (i=0;i<a;i++) as[0].push(0); //将 每种的桌子数 入队
            for (i=0;i<b;i++) as[1].push(0);
            for (i=0;i<c;i++) as[2].push(0);
            t[0]=t[1]=t[2]=n=0;
            while(scanf("%s",s)==1&&s[0]!='#')
            {
                e=0;
                scanf("%d",&d);
                e=600*(s[0]-'0')+60*(s[1]-'0')+10*(s[3]-'0')+(s[4]-'0');
                if(d==1||d==2)
                {
                    if(!as[0].empty())//判断  对是否 为空  也就是 桌子数是不是为零
                    {
                        if(as[0].top()<=e+30)   //如果  刚来的时间在加30分钟的 大于队列中最先走的时间   可入队
                        {
                            e=max(e,as[0].top());  //判断 时间大小 选择入队时间   如果 刚来的时间e大于  队列中最先走的时间  就 e+30 入队
                            if(e+30<=23*60)  //判断是否在营业
                            {
                                as[0].pop();
                                as[0].push(e+30);
                                n+=d;
                            }
                        }
                    }
                }
                else if(d==3||d==4)//同上
                {
                    if(!as[1].empty())
                    {
                        if(as[1].top()<=e+30)
                        {
                            e=max(e,as[1].top());
                            if(e+30<=23*60)
                            {
                                as[1].pop();
                                as[1].push(e+30);
                                n+=d;
                            }
                        }
                    }
                }
                else
                {
                   if(!as[2].empty())
                    {
                        if(as[2].top()<=e+30)
                        {
                            e=max(e,as[2].top());
                            if(e+30<=23*60)
                            {
                                as[2].pop();
                                as[2].push(e+30);
                                n+=d;
                            }
                        }
                    }
                }
            }
            printf("%d
    ",n);
            for(i=0;i<3;++i)//清空队列
                while(!as[i].empty())
                    as[i].pop();
        }
        return 0;
    }
    

    简单代码 ~~(>_<)~~

    #include<stdio.h>
    #include<iostream>
    #include<algorithm>
    #include<map>
    #include<queue>
    #include<stack>
    #include<vector>
    #include<cstdlib>
    #include<functional>
    using namespace std;
    int a, b, c, tot, t, sum, ans = 0;
    char s[20];
    
    int main()
    {
        while (scanf("%d%d%d", &a, &b, &c), a + b + c)
        {
            ans = 0;
            priority_queue<int, vector<int>, greater<int> > p[3];
            for (int i = 0; i < a; i++) p[0].push(0);
            for (int i = 0; i < b; i++) p[1].push(0);
            for (int i = 0; i < c; i++) p[2].push(0);
            while (scanf("%s", s), s[0] != '#')
            {
                t = 600 * s[0] + 60 * s[1] + 10 * s[3] + s[4] - '0' * 671;
                scanf("%d", &sum);
                tot = (sum - 1) / 2;
                if (!p[tot].empty())
                {
                    int q = p[tot].top(); 
                    if (q <= t + 30)
                    {
                        q = max(q, t) + 30;
                        if (q <= 23 * 60)
                        {
                            p[tot].pop();
                            p[tot].push(q);
                            ans += sum;
                        }
                    }
                }
            }
            printf("%d
    ", ans);
        }
    }
  • 相关阅读:
    【Java】抽象类、接口
    【Java】封装、继承、多态
    【Java】WrapperClass 包装类
    【Java】步入OOP 面向对象
    【MySQL】Windows8.0.19 解压版 下载安装
    【Java】05 Variable 变量
    【MySQL】更改root根用户密码 和 SQLyog安装
    LOJ2033.[SDOI2016]生成魔咒 (后缀自动机)
    HDU4641 Kstring (后缀自动机+线段树合并)
    HDU5853 Jong Hyok and String (广义后缀自动机)
  • 原文地址:https://www.cnblogs.com/nanfenggu/p/7900188.html
Copyright © 2011-2022 走看看