hdoj 4884 & BestCoder #2 1003
来源:互联网 发布:为什么程序员喜欢自黑 编辑:程序博客网 时间:2024/05/16 08:23
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)
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 个人;顺序已经排好了,当然是先到先得了;
每行的开始是他到来的时间, 接下来一个是他要的饭的类型,一个是他要的饭的碗数;输出每个人等饭的结束时间;
注意两点:1>下面这一组数据:
2 5 5 3
08:06 1 8 做他的第二轮的时候,顺便把三号的也可以做了(可以这样的)他的第一轮结束时间: 08:11
08:06 1 8 做他的第二轮的时候,顺便把三号的也可以做了(可以这样的)他的第一轮结束时间: 08:11
因为在第一轮结束之前,第三号已经来了,他只要一份饭,而一号还需要3份,厨师做四份饭即可
08:07 2 11
08:08 1 1
08:07 2 11
08:08 1 1
所以结果为
08:16
08:31
08:16
2>当时间过了一天了,就是出现:23:59、、、、、之类的要处理;
AC代码:(有参考别人的)
#include<cstdio>#include<cstring>#include<algorithm>#include<cstdlib>using namespace std;const int N = 1010;const int lim = 24*60;int T, n, t, k, m;int type[N];//表示上一个顾客走后,第N种饭的空缺;int last[N];//开始做上一个顾客,最后一轮饭的时间void print(int time){ if(time>=lim) time%=lim; printf("%02d:%02d\n", time/60, time%60);}int main(){ scanf("%d", &T); while(T--){ scanf("%d %d %d %d", &n, &t, &k, &m); memset(type,0,sizeof(type)); int hh, mm, a, b; int cur = 0; for(int i=0; i<m; i++){ scanf("%d:%d %d %d", &hh, &mm, &a, &b); hh = hh*60+mm; /*如果a钟饭还能做的份数,大于b, 并且这一轮的开始时间大于他来的时间 例如:2 5 5 3 08:06 1 8 做他的第二轮的时候,顺便把三号的也做了(可以这样) 08:07 2 11 08:08 1 1 */ if(type[a]>=b && last[a]>=hh) { type[a]-=b; print(last[a]+t); continue; } //如果上一轮剩余的不够了,就先把剩余的减去; if(type[a] && last[a]>=hh){ b-=type[a]; } int x = (b-1)/k + 1;//做他的饭需要的总时间 cur = max(cur, hh) + t*x; print(cur); type[a] = x * k - b;//类型剩余量 last[a] = cur - t;//做最后一轮饭的开始时间 } if(T) puts(""); } return 0;}
0 0
- hdoj 4884 & BestCoder #2 1003
- 【HDOJ】【BestCoder 2nd Anniversary】1003 Wool
- 【BestCoder】 HDOJ 5088
- 【BestCoder】 HDOJ 5101 Select
- 【BestCoder】 HDOJ 5103 RootedTree
- 【BestCoder】 HDOJ 5167 Fibonacci
- 20140916 【 贪心 】 bestcoder #2 + hdoj 4883 TIANKENG’s restaurant
- BestCoder Round #54 (div.2) HDOJ 5429 Geometric Progression(模拟)
- BestCoder Round #74 (div.2) T2 DFS HDOJ 5636
- BestCoder Round #74 (div.2) T3 Transform HDOJ 5637
- BestCoder Round #74 (div.2) T4 Toposort HDOJ 5638
- hdoj BestCoder Round #81 (div.2) AA Machine
- hdoj 【BestCoder Round #81 (div.2)】 5670 Machine
- 【BestCoder】 HDOJ 5056 Boring count
- 【BestCoder】 HDOJ Operation the Sequence
- 【BestCoder】 HDOJ 5163 Taking Bus
- 【BestCoder】 HDOJ 5174 Ferries Wheel
- 【BestCoder】 HDOJ 5233 Gunner II
- 笔记
- Android创建启动画面
- shared_ptr解析
- 路虎车主雨中扶老太 称最多讹钱讹不了命
- 3、CRM2011编程实战——选项集(下拉框)联动效果的实现
- hdoj 4884 & BestCoder #2 1003
- 已知程序crash 地址来分析具体crash 代码
- Linux shell脚本的字符串截取
- 夏季的饮食禁忌有哪些
- Shank大步小步算法
- SQL 优化原则
- Android-Fragment中TextView.setFocusable(true)导致的内存泄露
- hdu1207 优化后的,四柱汉诺塔
- public private 和protected 继承