HDU 4884 Bestcoder#2-1002 TIANKENG’s rice shop【模拟一发】

HDU 4884 Bestcoder#2-1002 TIANKENG’s rice shop【模拟一发】http://acm.hdu.edu.cn/showproblem.php?pid=4884

Problem Description
TIANKENG managers a pan fried rice shop. There are n kinds of fried rice numbered 1-n. TIANKENG will spend t time for once frying. Because the pan is so small, TIANKENG can fry k bowls of fried rice with same kind at most. Assuming that there are m customers coming to the shop, and we know the arriving time of each customer and the brand and number of the fried rice they need. Could you tell TIANKENG the departure time of every customer respectively? Pay attention that TIANKNEG will serve the customer who comes earlier and he will fry the rice as much as possible. Meanwhile, customers are in queue depending on their arriving time(the earlier they arrive, the more front they stand).
 

Input
The first line contains a positive integer T(T<=100), referring to T test cases.
For each test case, the first line has 4 positive integer n(1<=n<=1000), t(1<=t<=10), k(1<=k<=5), m(1<=m<=1000), then following m lines , each line has a time(the time format is hh:mm, 0<=hh<=23, 0<=mm<=59) and two positive integer id(1<=id<=n), num(1<=num<=10), which means the brand number of the fried rice and the number of the fried rice the customer needs.
Pay attention that two or more customers will not come to the shop at the same time, the arriving time of the customer will be ordered by the time(from early time to late time)
 

Output
For each test case print m lines, each line contains a time referring to the departure time of the customer. There is a blank line between two test cases.
 

Sample Input
  
  
3 2 1 4 2 08:00 1 5 09:00 2 1 2 5 4 3 08:00 1 4 08:01 2 2 08:02 2 2 2 5 4 2 08:00 1 1 08:04 1 1
 

Sample Output
  
  
08:02 09:01 08:05 08:10 08:10 08:05 08:10
 

Source
 
【题意】一家饭店有n种炒饭,编号1——n,一次用时 t 时间可烹饪同种炒饭 k 份,已知有 m 个顾客前来,知道他们的到达时间hh:mm、需要的炒饭类型 id 及数量 num;先到先得,分别输出他们的离开时间;两组输出之间空行。
【注意】时间是在00:00——23:59;有可能顾客在第二天凌晨离开;
      用an【1...】保存顾客到来时所选的炒饭种类的最大剩余量,last【1...】保存该种炒饭的最近次烹饪的开始时间;①顾客到来时,此次烹饪未开始,并且最大剩余量满足需求,则直接输出 print(last[id]+t) ;② 顾客到来时,此次烹饪未开始,并且最大剩余量小于需求,则 num -= an[id]; 按一般情况继续处理;③一般情况,time为上一个顾客离开时间,now为此时顾客到来时间,两者去最大max,求烹饪次数(向上取整)f = (int)ceil((double)num/(double)k);更新last,time,an;输出time即可!
【代码如下】
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>


using namespace std;


const int inf = 60*24;


int hh,mm,id,num;
int T,n,t,k,m,time;
int an[2000];
int last[2000];


void print(int ttime)
{
    ttime = ttime%inf;
    int hhh = ttime/60;
    int mmm = ttime%60;
    printf("%02d:%02d\n",hhh,mmm);
    return;
}


int main()
{
    cin>>T;
    int tt=1;
    while(T--)
    {
        if(tt!=1) puts("");
        tt++;
        cin>>n>>t>>k>>m;
        memset(an, 0, sizeof(an));
        memset(last, 0, sizeof(last));
        time = 0;
        for(int i=0; i<m; i++)
        {
            scanf("%d:%d %d %d",&hh,&mm,&id,&num);
            int now = hh*60+mm;
            time = max(time, now);
            if(now <= last[id] && an[id] >= num){
                an[id] -= num;
                print(last[id]+t);
                continue;
            }
            if(now <= last[id] && an[id])
                num -= an[id];


            int f = (int)ceil((double)num/(double)k);
            an[id] = f*k - num;
            time += (f*t);
            last[id] = time-t;
            print(time);
        }
    }
    return 0;
}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值