【CUGBACM15级BC第二场 B】hdu 4884 TIANKENG’s rice shop

来源:互联网 发布:mac修改移动硬盘权限 编辑:程序博客网 时间:2024/06/01 08:38

TIANKENG’s rice shop

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1315    Accepted Submission(s): 326


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个顾客的信息,进店时间,炒饭的编号以及份数。然后要输出每个顾客离开的时间。

题目中告诉了我们炒饭的规则,按照先来先服务,但是每次炒会炒尽可能多的份数,不过不会有多余的。

举个例子,比如每次可以炒5份,每次5分钟。

第一个顾客08:00进来,点了2份A,

第二个顾客08:04进来,点了3份A。

在08:00开始炒的话,由于这个时候第二个顾客还没进来,所以就只炒2份,第一个顾客在08:05离开,这时才炒第二个的3份,所以第二个离开时间是08:10。

同样是每次可以炒5份,每次5分钟。

第一个顾客08:00进来,点了6份A,

第二个顾客08:01进来,点了5份B,

第三个顾客08:02进来,点了4份A。

同样地,先炒5份给第一个,还差一份,这是已经是08:05了,第三个顾客也进来了,所以这时直接炒5份A(因为会尽可能多地炒),08:10第一个和第三个可以同时离开。接着才炒第二个的。

具体模拟的话,我是用一个cnt[i]表示编号i的炒饭还剩下多少份,并且最后一次炒的时间last[i]。

那么读到一个时间hh:mm,先判断这个编号的炒饭有没有剩余,进来的时间是否比最后一次炒的时间早,只有比这个时间早才有可能提前为他炒。

如果剩余的数量足以供应了,就直接输出last[i]+t

否则求出剩余的量还需要的时间,并且更新cnt[i]和last[i]。


然后这题还有一个trick的地方(至少SB的我是被卡在这里的= =),就是有可能进店的时间和出店的时间不在同一天,比如23:59进来,炒饭用了5分钟,离开的时候是00:04而不是24:04,我因为先将时间换成分钟计算,最后转换回来时没有判断WA掉

#include <iostream>#include <set>#include <map>#include <stack>#include <cmath>#include <queue>#include <cstdio>#include <bitset>#include <string>#include <vector>#include <iomanip>#include <cstring>#include <algorithm>#include <functional>#define PI acos(-1)#define eps 1e-8#define inf 0x3f3f3f3f#define debug(x) cout<<"---"<<x<<"---"<<endltypedef long long ll;using namespace std;int a[1010];int main(){    int gg;    cin >> gg;    while (gg--)    {        memset(a, 0, sizeof(a));        int n, t, k, hh;        cin >> n >> t >> k >> hh;        for (int i = 0; i < hh; i++)        {            int h, m, kind, countt, wt=0;            scanf("%d:%d%d%d", &h, &m, &kind, &countt);            if (a[kind] >= countt)            {                a[kind] -= countt;                countt = 0;                wt = 0;            }            else            {                countt -= a[kind];                a[kind] = 0;            }            if (countt % k == 0 && countt)            {                wt += (countt / k) * t;                a[kind] += 0;            }            else if (countt % k != 0 && countt)            {                wt += ((countt / k) + 1) * t;                a[kind] += ((countt / k) + 1) * k - countt;            }            m += wt;            if (m >= 60)            {                h++;                if (h == 25)                {                    h = 1;                }                m -= 60;            }            if (h >= 0 && h <= 9)            {                printf("0%d:", h);            }            else            {                printf("%d", h);            }            if (m >= 0 && m <= 9)            {                printf("0%d\n", m);            }            else            {                printf("%d\n", m);            }        }        cout << endl;    }    return 0;}