hdu--4884--TIANKENG’s rice shop【模拟】

来源:互联网 发布:唯一视觉婚纱摄影 知乎 编辑:程序博客网 时间:2024/06/05 05:24

TIANKENG’s rice shop

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


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,给出m个客人到店里的时间点,要的炒饭的种类以及多少碗,让你求出在速度最快的情况下,每位客人离开的时间

解题思路:

每一次炒的时候,记录下开始炒这种炒饭的时间,以及锅里还可以多炒几碗,当每一次顾客来的时候,都先比较一下顾客点餐的时间以及最后一次炒这种饭的时间,如果顾客来的时间在最后炒这种饭之前,就放在一起炒,因为上一次锅里剩下的空间还能放多少碗不知道,先比较一下,如果剩下的空间可以炒完,就直接炒完,如果不能就尽量多的炒,剩下的再炒一锅,别忘了记录最后炒这种炒饭开始的时间,以及锅里还剩下多少空间,以便下一次顾客来的时候进行比较。

代码:

(转自:http://blog.csdn.net/loy_184548/article/details/50562331)

 C++ Code 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include <bits/stdc++.h>
using namespace std;
int last_time[1005];  ///用于记录最后一次炒i号炒饭的时间
int last_cnt[1005];   ///用于记录最后一次炒i份饭还剩下多少份

int lim = 24 * 60;
void print(int time)
{
    if (time >= lim)
        time %= lim;   ///注意时间的转化
    int hour = time / 60;
    int mins = time % 60;
    printf("%02d:%02d\n", hour, mins);
}

int main()
{
    int T;
    cin >> T;
    while(T--)
    {
        int n, t, k, m;
        memset(last_time, 0sizeof(last_time));
        memset(last_cnt, 0sizeof(last_cnt));
        scanf("%d%d%d%d", &n, &t, &k, &m);
        int finish = 0;
        for (int i = 0; i < m; i++)
        {
            int h, mins, id, num;
            scanf("%d:%d %d%d", &h, &mins, &id, &num);
            int time = h * 60 + mins;  ///便于计算

            if (time <= last_time[id] && num <= last_cnt[id])   ///如果当前时间<最后一次炒饭的时间并且能直接炒完
            {
                last_cnt[id] -= num;
                print(last_time[id] + t);  ///输出上一次炒饭时间 + 炒饭需要的时间
                continue;
            }
            else if (time <= last_time[id] && last_cnt[id]) ///如果当前时间<最后一次炒饭的时间但是不能直接炒完
                ///(先把能炒的提前炒掉,剩余部分轮到的时候再炒)
            {
                num -= last_cnt[id];
            }
            int need = (num / k + (num % k ? 1 : 0)) * t;  ///炒完需要的时间
            finish = max(finish, time) + need; ///判断到达的时间和排队的时间(上一个人完成的时间) + 炒饭需要的时间 = 这个人完成的时间
            print(finish);
            last_cnt[id] = need / t  * k - num;    ///每一次都炒最多的,剩下的后面有需要的话 直接拿
            last_time[id] = finish - t;            ///最后一次炒饭开始的时间,
        }
        if (T)
            puts("");
    }
    return 0;
}



原创粉丝点击