POJ 2424 Flo's Restaurant (模拟)

POJ 2424 Flo’s Restaurant

题目传送门

题意:

你在开一个餐厅,共有三种桌子,第一种:只能坐1~2个人,第二种:只能坐3~4个人,第三种:只能做5~6个人,每种桌子分别有A、B、C张,有一些客人会来吃饭,但可能会出现客人会等待的情况。假设每桌都要吃半小时,如果一个客人需要等的时间多余半小时,那么他们就会离开,给出你这些客人到达的时间,问你总共能够招待多少客人。

解题过程:

比较简单的模拟,注意时间的处理就行了。我的代码感觉很烂,由于懒得手写队列,于是就暴力的表里了一遍,导致这题的空间直接扩大了三倍,只是题目数据小,很容易就过了,不过还是不推荐我的代码……

AC代码:

#pragma GCC optimize (3)
#include <cstdio>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <queue>
#include <set>
#include <map>
#include <list>
#include <vector>
#include <cstdlib>
#include <cstring>
using namespace std;
const int maxn=200;
typedef pair<int,int>P;
#define fi first
#define se second

int A,B,C;
int h,m;
int cnt;
queue<P>a,b,c;

inline int gettime(int h1,int m1,int h2,int m2) {
    int ans=0;
    ans+=(h2-h1)*60+m2-m1;
    return ans;
}

int main() {
    while(scanf("%d%d%d",&A,&B,&C)&&A&&B&&C) {
    int ans=0;
    while(!a.empty())a.pop();
    while(!b.empty())b.pop();
    while(!c.empty())c.pop();
    while(1) {
        char ch=getchar();
        while(ch==' '||ch=='
'||ch=='
') {
        ch=getchar();
        }
        if(ch=='#')break;
        scanf("%d:%d",&h,&m);
        int xx=ch-'0';
        h=xx*10+h;
        scanf("%d",&cnt);
        if(cnt>=1&&cnt<=2) {
        int cc=a.size();
        for(int i=1;i<=cc;i++) {
            P t=a.front();
            a.pop();
            int tt=gettime(t.fi,t.se,h,m);
            if(tt<30) {
            a.push(P(t.fi,t.se));
            }
        }
        int peop=a.size();
        if(peop<A) {
            a.push(P(h,m));
            ans+=cnt;
        }
        else {
            int mint=0x3f3f3f3f;
            int cc=a.size();
            int pos;
            for(int i=1;i<=cc;i++){
            P t=a.front();
            a.pop();
            int tt=gettime(t.fi,t.se,h,m);
            tt=30-tt;
            if(mint>tt) {
                mint=tt;
                pos=i;
            }
            a.push(P(t.fi,t.se));
            }
            if(mint<=30) {
            for(int i=1;i<pos;i++){
                P t=a.front();
                a.pop();
                a.push(P(t.fi,t.se));
            }
            a.pop();
            m+=mint;
            if(m>=60)m-=60,h+=1;
            a.push(P(h,m));
            ans+=cnt;
            }
        }
        }

        if(cnt>=3&&cnt<=4) {
        int cc=b.size();
        for(int i=1;i<=cc;i++) {
            P t=b.front();
            b.pop();
            int tt=gettime(t.fi,t.se,h,m);
            if(tt<30) {
            b.push(P(t.fi,t.se));
            }
        }
        int peop=b.size();
        if(peop<B) {
            b.push(P(h,m));
            ans+=cnt;
        }
        else {
            int mint=0x3f3f3f3f;
            int cc=b.size();
            int pos;
            for(int i=1;i<=cc;i++){
            P t=b.front();
            b.pop();
            int tt=gettime(t.fi,t.se,h,m);
            tt=30-tt;
            if(mint>tt) {
                mint=tt;
                pos=i;
            }
            b.push(P(t.fi,t.se));
            }
            if(mint<=30) {
            for(int i=1;i<pos;i++){
                P t=b.front();
                b.pop();
                b.push(P(t.fi,t.se));
            }
            b.pop();
            m+=mint;
            if(m>=60)m-=60,h+=1;
            b.push(P(h,m));
            ans+=cnt;
            }
        }
        }

        if(cnt>=5&&cnt<=6) {
        int cc=c.size();
        for(int i=1;i<=cc;i++) {
            P t=c.front();
            c.pop();
            int tt=gettime(t.fi,t.se,h,m);
            if(tt<30) {
            c.push(P(t.fi,t.se));
            }
        }
        int peop=c.size();
        if(peop<C) {
            c.push(P(h,m));
            ans+=cnt;
        }
        else {
            int mint=0x3f3f3f3f;
            int cc=c.size();
            int pos;
            for(int i=1;i<=cc;i++){
            P t=c.front();
            c.pop();
            int tt=gettime(t.fi,t.se,h,m);
            tt=30-tt;
            if(mint>tt) {
                mint=tt;
                pos=i;
            }
            c.push(P(t.fi,t.se));
            }
            if(mint<=30) {
            for(int i=1;i<pos;i++){
                P t=c.front();
                c.pop();
                c.push(P(t.fi,t.se));
            }
            c.pop();
            m+=mint;
            if(m>=60)m-=60,h+=1;
            c.push(P(h,m));
            ans+=cnt;
            }
        }
        }
    }
    printf("%d
",ans);
    }
    return 0;
}

本人蒟蒻OIer一枚,欢迎加QQ:840776708一起学习蛤。

「我不敢下苦功琢磨自己,怕终于知道自己并非珠玉;然而心中既存着一丝希冀,便又不肯甘心与瓦砾为伍。」
原文地址:https://www.cnblogs.com/Apocrypha/p/9433663.html