HDU 4884 TIANKENG’s rice shop (類比)__類比

來源:互聯網
上載者:User
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

32 1 4 208:00 1 509:00 2 12 5 4 308:00 1 408:01 2 208:02 2 22 5 4 208:00 1 108:04 1 1


Sample Output

08:0209:0108:0508:1008:1008:0508:10


題意

有n種炒飯,每次炒的時間是t分鐘,每次最多炒k份,然後按照進店的順序給出m個顧客的資訊,進店時間,炒飯編號以及份數,輸出每個顧客離開的時間。


思路

顧客是先來先服務,並且每次會儘可能多的去炒。

我們可以儲存上次炒飯可以容納的份數以及開炒時間,如果時間晚於當前顧客的到來時間,則把當前顧客的份添加進去一起做,如果有剩餘的份,則單獨計算離開時間,並維護儲存這兩個值。


AC 代碼

#include<iostream>#include<algorithm>#include<stdio.h>#include<string.h>#include<math.h>#include<iostream>using namespace std;#include<queue>#include<stack>int sk[1100],lt[1100];int main(){    int T;    scanf("%d",&T);    for(int ti=1; ti<=T; ti++)    {        int n,t,k,m,time=0;        scanf("%d%d%d%d",&n,&t,&k,&m);        memset(sk,0,sizeof(sk));    //上次炒飯還可以容納的份數        memset(lt,0,sizeof(lt));    //上次炒飯開始的時間        for(int i=0; i<m; i++)        {            int hour,minutm,id,num,ci;            scanf("%d%*c%d%d%d",&hour,&minutm,&id,&num);            hour=hour*60+minutm;            if(lt[id]>=hour)        //如果顧客早於開始炒飯的時間            {                if(sk[id]>=num)     //當前顧客的份可以加到前面一起炒                {                    sk[id]-=num;//                    cout<<lt[id]+t<<endl;                    int time=(lt[id]+t)%1440;   //因為可能會到第二天,所以需要%1440                    printf("%02d:%02d\n",time/60,time%60);                    continue;                }                else num-=sk[id];   //當前顧客部分份和前面的一起            }            ci=(num-1)/k+1;         //還需要幾次            time=max(time,hour)+t*ci;   //計算離開的時間            printf("%02d:%02d\n",(time%1440)/60,(time%1440)%60);            if(num%k==0)sk[id]=0;   //如果炒的過程中沒有多餘            else sk[id]=k-num%k;    //還可以添加幾份一起炒            lt[id]=time-t;          //當前開始炒飯時間        }        if(ti!=T)printf("\n");    }    return 0;}

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.