hdu 1103 flo restaurant

简单题,排队模型队列模式。
主要是输入有点麻烦,scanf(“%c”) 输入总会接收把空格和换行。要注意用getchar()过滤。

AC代码

#include <iostream>
#include<vector>
#include<cstring>
#include<cstdio>
#include<queue>
using namespace std;
#define MAX 5000

int tm[MAX];
int p[MAX];

struct Node{

    int arrive;
    int person;

};

int a,b,c;

int two[100];
int four[100];
int six[100];
queue<Node> qa;
queue<Node> qb;
queue<Node> qc;

int handleA(){

    memset(two,0,sizeof(two));

    int mm=1000000;
    int total=0;
    Node tmp;
    while(!qa.empty()){
         tmp=qa.front();
         qa.pop();
        mm=1000000;
        int index=-1;
        for(int i=0;i<a;i++){

            if(two[i]<mm){
                mm=two[i];
                index=i;
            }
        }
        if(mm==0){
            two[index]=tmp.arrive;
            total+=tmp.person;
        }else if(mm<=tmp.arrive&&mm<=22*60){
           if(mm+30<tmp.arrive)
                two[index]=tmp.arrive;
            else
                two[index]=mm+30;
            total+=tmp.person;
        }
    }
    return total;

}
int handleB(){

    int n=qb.size();
    memset(four,0,sizeof(four));

    int mm=1000000;
    int total=0;
    int cnt=0;
    Node tmp;
    while(!qb.empty()){


         tmp=qb.front();
         qb.pop();
        mm=1000000;
        int index=-1;
        for(int i=0;i<b;i++){

            if(four[i]<mm){
                mm=four[i];
                index=i;
            }
        }
        if(mm==0){
            four[index]=tmp.arrive;
            total+=tmp.person;
        }else if(mm<=tmp.arrive&&mm<=22*60){
           if(mm+30<tmp.arrive)
                four[index]=tmp.arrive;
            else
                four[index]=mm+30;
            total+=tmp.person;
        }
    }
    return total;
}

int handleC(){

    int n=qc.size();
    memset(six,0,sizeof(six));

    int mm=1000000;
    int total=0;
    int cnt=0;
    Node tmp;
    while(!qc.empty()){


         tmp=qc.front();
         qc.pop();
        mm=1000000;
        int index=-1;
        for(int i=0;i<c;i++){

            if(six[i]<mm){
                mm=six[i];
                index=i;
            }
        }
        if(mm==0){
            six[index]=tmp.arrive;
            total+=tmp.person;
        }else if(mm<=tmp.arrive&&mm<=22*60){
            if(mm+30<tmp.arrive)
                six[index]=tmp.arrive;
            else
                six[index]=mm+30;

            total+=tmp.person;
        }

    }
    return total;

}



int main()
{


    while(cin>>a>>b>>c){
        while(!qa.empty())qa.pop();
        while(!qb.empty())qb.pop();
        while(!qc.empty())qc.pop();
        if(a==0&&b==0&&c==0) break;

        char h1,h2;
        int m;
        int n;
        getchar();
        int i=0;
        string s;
        while(true){
            cin>>s;
            if(s[0]=='#') break;
            char h1=s[0];
            char h2=s[1];
            char m1=s[3];
            char m2=s[4];
            cin>>n;

           int h=(int)(h1-'0')*10+(int)(h2-'0');
          int m=(int)(m1-'0')*10+(int)(m2-'0');
           int t=h*60+m;

           tm[i]=t;
           p[i]=n;
           i++;
           Node tmp;
           tmp.arrive=t;
           tmp.person=n;

           if(n<=2)qa.push(tmp);
           else if(n>2&&n<=4) qb.push(tmp);
           else if(n>4&&n<=6) qc.push(tmp);

        }
        // total i
        int total=handleA()+handleB()+handleC();
       cout<<total<<endl;
    }
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值