题目链接:
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 1Sample Output
08:02
09:0108:05
08:10 08:1008:05
08:10题意:
有一个炒饭店:
有n种炒饭; 每次可以同时炒k个同类炒粉, 且耗时为t; 假设每次炒饭都会炒足k个(不管有没有有人要); 现有m个客人:记录每种产品最后一次制作的开始时间和该产品剩余的份数;给出每个客人到达的时间; 需要的品种(一个人只要一种)和份数;
现在要求出每个客人的离开时间. 注意: m个客人按照到点排序,依次供应每个客人. 若制作某次炒粉前,有多个客人已经到达并且需要同种炒粉,则可以同时制作;对于样例2:制作品种2时,第3个客人已达到,则可以同时制作两人的;
对于样例3:制作第一个客人的炒饭(品种1)时,第二个客人还没有到达,所以不能提前制作.题解:
直接模拟整个过程:
方便起见,将所有时间以分钟计数;(输出时注意处理hour>=24的情况) 假设每次炒饭都会炒足k个(不管有没有有人要); 记录每种产品最后一次制作的开始时间和该产品剩余的份数;依次处理每个客人,对于客人i:
- 比较i达到时间和所需产品的最后制作时间,如果在制作之前就到达了,那么即可以将剩下的产品卖给他; 如果剩下的产品足够供应客人i,则不需要开始新的制作,此时客人i处理完毕;
- 若剩下的产品不足以供应i(先将剩下的都给他),或者i的到达时间在最后一次制作之后(剩下的产品不能卖给他): 则需要开始新的制作; 注意:新的制作开始的时间不一定是当前到达的时间,而是max(上一次制作(任意产品)的结束时间,当前时间); (所以每次新的制作都要更新结束时间)
代码:
#include#include #include #include #include #include #include