[ACM] HDU 4884 TIANKENG’s rice shop (模拟)

来源:互联网 发布:外国人发现淘宝 编辑:程序博客网 时间:2024/06/05 15:38

TIANKENG’s rice shop


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
 


 

Source

 

BestCoder Round #2
 


 

Recommend

 

liuyiding

解题思路:

这道模拟题太坑了......

一共有n种炒饭,每种炒饭炒一次都花t分钟,炒一次是k份的量,每次只能炒同一种炒饭,有m个客人,给出每个客人的到来时间,以及所要炒饭的种类和数量,问每个客人的最早离开时间.

一开始第三组测试数据没看懂

n=2 t=5 k=4 m=2

08:00 1 1

08:04 1 1

第一位客人8点的时候要了第一种炒饭1分,第二位客人8点04的时候要了第1种炒饭1份,那直接炒4份不就可以了吗...两位客人都是0点5分离开,坑啊,不能这样,正确的应该是这样联系实际,首先来的是第一位客人要了第一种炒饭1份,那么就得花5分钟就只炒1份,虽然这5分钟内有第二位客人来了,但是不能给他炒,等第一位客人走了以后,再给第二位客人来炒。

还有另外种情况,后面的可以加在前面炒

还是前面的数据,只不过客人的信息该为了

08:00 1 6

08:02 2 1

08:03 1 X

首先第一位客人,要了6份,因为一次最多炒4份,所以第一份炒完4份后,时间为8点05,这时候第二位和第三位都来了,正好第三位和第一位要的是一样的,那么下一次再为第一位客人炒饭(因为还差2份)时,就可以顺便为第三位客人也炒出来,如果X=2的话,那么最后一次为第一位客人炒饭,2份给它,2份给第三位个人就可以了,两位客人同时离开,如果X<2的话,假设为1,那么最后一次只要炒3份就可以了。如果X>2的话,那么炒出来2分给第三位客人留着,到了他的时候,再给他炒X-2份就够了.

写这道题,头晕晕的......

代码:

 

#include <iostream>#include <stdio.h>#include <algorithm>#include <string.h>#include <stdlib.h>#include <cmath>#include <iomanip>#include <vector>#include <set>#include <map>#include <stack>#include <queue>#include <cctype>using namespace std;#define ll long longconst int maxn=1002;//最大种类数int n,t,K,M;//n为种类数,t为一次炒饭的时间,k为一次可以炒多少份,m是有m个客人bool done[maxn];struct Customer{    int h,m;    int time;    int kind;    int num;    int ans;}cus[maxn];void output(int t){    int h=t/60;    h%=24;    int m=t%60;    if(h<=9)        printf("0%d:",h);    else        printf("%d:",h);    if(m<=9)        printf("0%d\n",m);    else        printf("%d\n",m);}int main(){    int T;scanf("%d",&T);    while(T--)    {        scanf("%d%d%d%d",&n,&t,&K,&M);        memset(done,0,sizeof(done));        for(int i=1;i<=M;i++)        {            scanf("%d:%d %d %d",&cus[i].h,&cus[i].m,&cus[i].kind,&cus[i].num);            cus[i].time=cus[i].h*60+cus[i].m;        }        int curtime=-1;//当前时间        for(int i=1;i<=M;i++)        {            if(done[i])                continue;            if(cus[i].time>=curtime)                curtime=cus[i].time;            int c=(cus[i].num)/K;//为第i个顾客需要炒几次饭            if(cus[i].num%K!=0)                c++;            //cout<<"tt"<<tt<<endl;            cus[i].ans=curtime+c*t;//第i个顾客离开时间            //int curt=curtime+cus[k].num/K*t;            int curt=cus[i].ans-t;//为第i个顾客最后一次炒饭开始的时间,            //因为这时候要看看后面的顾客有没有和当前顾客要的一样的,顺带着“炒出来一部分”            curtime=cus[i].ans;            int left=c*K-cus[i].num;//最后一次可以多炒一部分,比如每次炒4份,当前顾客要10份,那么得炒3次,第三次炒可以炒4份,那么就会多出来2份            done[i]=1;           // cout<<"kk"<<k<<"left"<<left<<endl;            for(int j=i+1;j<=M;j++)            {                if(cus[j].time>curt)                    break;                if(cus[j].kind!=cus[i].kind)                    continue;                if(left>=cus[j].num)//当前顾客多出的饭可以直接给后面需要的                {                   // cout<<"inininininin"<<endl;                    cus[j].ans=cus[i].ans;                    done[j]=1;                    left-=cus[j].num;                }                else                {                    cus[j].num-=left;                    left=0;                    break;                }            }            //kindn[cus[k].kind]+=left;            //cout<<cus[k].kind<<"  sssssssss   "<<left<<endl;        }        for(int i=1;i<=M;i++)            output(cus[i].ans);        if(T)        printf("\n");    }    return 0;}


 

 

0 0