码迷,mamicode.com
首页 > 其他好文 > 详细

HDOJ 4884 & BestCoder#2 1002

时间:2014-07-29 17:29:22      阅读:269      评论:0      收藏:0      [点我收藏+]

标签:des   style   blog   java   color   os   strong   io   

TIANKENG’s rice shop


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


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
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 1
 
Sample Output
08:02 09:01 08:05 08:10 08:10 08:05 08:10
题解:题目大意是说,炒米粉问题、、、有 N 种饭,每种饭做一轮耗时间为 T ,每一轮可以做 K 碗饭,下面是 M 个人;顺序已经排好了,当然是先到先得了;
每行的开始是他到来的时间, 接下来一个是他要的饭的类型,一个是他要的饭的碗数;输出每个人等饭的结束时间;
注意两点:1>下面这一组数据:
  2 5 5 3
                      08:06 1 8  做他的第二轮的时候,顺便把三号的也可以做了(可以这样的)他的第一轮结束时间: 08:11
   因为在第一轮结束之前,第三号已经来了,他只要一份饭,而一号还需要3份,厨师做四份饭即可
                      08:07 2 11
                       08:08 1 1
所以结果为
          08:16
          08:31
         08:16
2>当时间过了一天了,就是出现:23:59、、、、、之类的要处理;
AC代码:(有参考别人的)
 1 #include<cstdio>
 2 #include<cstring>
 3 #include<algorithm>
 4 #include<cstdlib>
 5 using namespace std;
 6 const int N = 1010;
 7 const int lim = 24*60;
 8 int T, n, t, k, m;
 9 int  type[N];//表示上一个顾客走后,第N种饭的空缺;
10 int  last[N];//开始做上一个顾客,最后一轮饭的时间
11 void print(int time)
12 {
13     if(time>=lim)   time%=lim;
14     printf("%02d:%02d\n", time/60, time%60);
15 }
16 int main(){
17     scanf("%d", &T);
18     while(T--){
19         scanf("%d %d %d %d", &n, &t, &k, &m);
20         memset(type,0,sizeof(type));
21         int hh, mm, a, b;
22         int cur = 0;
23         for(int i=0; i<m; i++){
24             scanf("%d:%d %d %d", &hh, &mm, &a, &b);
25             hh = hh*60+mm;
26             /*如果a钟饭还能做的份数,大于b,
27               并且这一轮的开始时间大于他来的时间
28               例如:2 5 5 3
29                     08:06 1 8  做他的第二轮的时候,顺便把三号的也做了(可以这样)
30                     08:07 2 11
31                     08:08 1 1
32               */
33             if(type[a]>=b && last[a]>=hh)
34             {
35                 type[a]-=b;
36                 print(last[a]+t);
37                 continue;
38             }
39             //如果上一轮剩余的不够了,就先把剩余的减去;
40             if(type[a] && last[a]>=hh){
41                 b-=type[a];
42             }
43             int x = (b-1)/k + 1;//做他的饭需要的总时间
44             cur = max(cur, hh) + t*x;
45             print(cur);
46             type[a] = x * k - b;//类型剩余量
47             last[a] = cur - t;//做最后一轮饭的开始时间
48         }
49         if(T)   puts("");
50     }
51     return 0;
52 }

 

HDOJ 4884 & BestCoder#2 1002,布布扣,bubuko.com

HDOJ 4884 & BestCoder#2 1002

标签:des   style   blog   java   color   os   strong   io   

原文地址:http://www.cnblogs.com/lovychen/p/3875733.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!