HDU 4884 TIANKENG’s rice shop (模拟)
TIANKENG’s rice shop
题目链接:
http://acm.hust.edu.cn/vjudge/contest/123316#problem/J
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种炒饭; 每次可以同时炒k个同类炒粉, 且耗时为t;
假设每次炒饭都会炒足k个(不管有没有有人要);
现有m个客人:记录每种产品最后一次制作的开始时间和该产品剩余的份数;
给出每个客人到达的时间; 需要的品种(一个人只要一种)和份数;
现在要求出每个客人的离开时间.
注意:
m个客人按照到点排序,依次供应每个客人.
若制作某次炒粉前,有多个客人已经到达并且需要同种炒粉,则可以同时制作;
对于样例2:制作品种2时,第3个客人已达到,则可以同时制作两人的;
对于样例3:制作第一个客人的炒饭(品种1)时,第二个客人还没有到达,所以不能提前制作.
题解:
直接模拟整个过程:
方便起见,将所有时间以分钟计数;(输出时注意处理hour>=24的情况)
假设每次炒饭都会炒足k个(不管有没有有人要);
记录每种产品最后一次制作的开始时间和该产品剩余的份数;
依次处理每个客人,对于客人i:
- 比较i达到时间和所需产品的最后制作时间,如果在制作之前就到达了,那么即可以将剩下的产品卖给他;
如果剩下的产品足够供应客人i,则不需要开始新的制作,此时客人i处理完毕; - 若剩下的产品不足以供应i(先将剩下的都给他),或者i的到达时间在最后一次制作之后(剩下的产品不能卖给他):
则需要开始新的制作;
注意:新的制作开始的时间不一定是当前到达的时间,而是max(上一次制作(任意产品)的结束时间,当前时间);
(所以每次新的制作都要更新结束时间)
代码:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
#include <vector>
#define LL long long
#define eps 1e-8
#define maxn 1100
#define inf 0x3f3f3f3f
#define IN freopen("in.txt","r",stdin);
using namespace std;
int n, t, k, m;
int start_time[maxn];
int last_num[maxn];
int ans[maxn];
int last_time;
int main(int argc, char const *argv[])
{
//IN;
int T; scanf("%d", &T);
while(T--)
{
memset(start_time, 0, sizeof(start_time));
memset(last_num, 0, sizeof(last_num));
memset(ans, -1, sizeof(ans));
last_time = 0;
scanf("%d %d %d %d", &n, &t, &k, &m);
for(int i=1; i<=m; i++) {
int t1,t2,type,num;
scanf("%d:%d %d %d", &t1,&t2,&type,&num);
int _time = t1 * 60 + t2;
if(_time <= start_time[type] && last_num[type]) {
//可以将剩下的卖给客人
if(num <= last_num[type]) {
last_num[type] -= num;
ans[i] = start_time[type] + t;
} else {
num -= last_num[type];
last_num[type] = 0;
}
}
if(ans[i] != -1) continue;
int ci = num / k; if(num%k) ci++;
start_time[type] = max(_time, last_time) + (ci-1)*t; //新制做的开始时间:max(_time, last_time);
last_time = start_time[type] + t;
last_num[type] = k*ci - num;
ans[i] = last_time;
}
for(int i=1; i<=m; i++) {
int hours = ans[i] / 60;
hours %= 24;
int mins = ans[i] % 60;
printf("%02d:%02d\n", hours, mins);
}
//PE: 最后一个用例后不能输出回车.
if(T) printf("\n");
}
return 0;
}
HDU 4884 TIANKENG’s rice shop (模拟)的更多相关文章
- hdu 4884 TIANKENG’s rice shop(模拟)
# include <cstdio> # include <algorithm> # include <cstring> # include <cstdlib ...
- HDU TIANKENG’s rice shop(模拟)
HDU 4884 TIANKENG's rice shop 题目链接 题意:模拟题.转一篇题意 思路:就模拟就可以.注意每次炒完之后就能够接单 代码: #include <cstdio> ...
- 【HDOJ】4884 TIANKENG's rice shop
简单模拟,注意并不是完全按照FIFO的顺序.比如第i个人的id为k,那么就算第i+1人的id不为k,也会检查他后续的排队人是否有id为k的. #include <cstdio> #incl ...
- TIANKENG’s rice shop
Problem Description TIANKENG managers a pan fried rice shop. There are n kinds of fried rice numbere ...
- hdu 4885 TIANKENG’s travel(bfs)
题目链接:hdu 4885 TIANKENG's travel 题目大意:给定N,L,表示有N个加油站,每次加满油能够移动距离L,必须走直线,可是能够为斜线.然后给出sx,sy,ex,ey,以及N个加 ...
- hdu 4122 Alice's mooncake shop(单调队列)
题目链接:hdu 4122 Alice's mooncake shop 题意: 有n个订单和可以在m小时内制作月饼 接下来是n个订单的信息:需要在mon月,d日,year年,h小时交付订单r个月饼 接 ...
- HDU 4883 TIANKENG’s restaurant Bestcoder 2-1(模拟)
TIANKENG's restaurant Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/65536 K (Java/O ...
- HDU 5102 The K-th Distance(模拟)
题意:输入一棵树,输出前k小的点对最短距离dis(i,j)的和. 模拟,官方题解说得很清楚了.不重复了. http://bestcoder.hdu.edu.cn/ 需要注意的是,复杂度要O(n+k), ...
- HDU 5805 NanoApe Loves Sequence (模拟)
NanoApe Loves Sequence 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5805 Description NanoApe, the ...
随机推荐
- DataGridView控件的使用---添加行
最简单的方法 可以静态绑定数据源,这样就自动为DataGridView控件添加相应的行. 假如需要动态为DataGridView控件添加新行,方法有很多种,下面简单介绍如何为DataGridView控 ...
- Oracle过程包加密
Oracle加绕功能可以将PL/SQL代码实现部分隐藏,如存储过程.函数.包体等均可使用加绕功能,下面以一个存储过程实现部分加绕来展示Oracle加绕功能的使用. 加绕方法一: 1.编写如下存储过程 ...
- [POJ1236]Network of Schools(并查集+floyd,伪强连通分量)
题目链接:http://poj.org/problem?id=1236 这题本来是个强连通分量板子题的,然而弱很久不写tarjan所以生疏了一下,又看这数据范围觉得缩点这个事情可以用点到点之间的距离来 ...
- hdu 1885 Key Task (三维bfs)
题目 之前比赛的一个题, 当时是崔老师做的,今天我自己做了一下.... 还要注意用bfs的时候 有时候并不是最先到达的就是答案,比如HDU 3442 这道题是要求最小的消耗血量伤害,但是并不是最先到 ...
- bzoj1834: [ZJOI2010]network 网络扩容
努力看了很久样例一直过不了...然后各种输出中间过程啊巴拉巴拉弄了1h,没办法了...然后突然想到啊原来的边可以用啊为什么不用...于是A了...感人肺腑 #include<cstdio> ...
- 《分销系统-原创第一章》之“多用户角色权限访问模块问题”的解决思路( 位运算 + ActionFilterAttribute )
此项目需求就是根据给用户分配的权限,进行相应的权限模块浏览功能,因为项目不是很大,所以权限没有去用一张表去存,我的解决思路如下,希望大家给点建议. 数据库用户表结构如下: 数据库表梳理: BankUs ...
- apache开源项目-- Turbine
1.缘起 Jetspeed是Apache Jakarta小组的开放源码门户系统.它使得最终用户可以通过WAP手机.浏览器.PDA等各种设备来使用各种各样的网络资源(比如应用程序.数据以及这之外的任何网 ...
- 再一次见证mssql中in 与exist的区别
见下面代码 /*+' select * from '+@strDBName +'.dbo.m_aic where nodeid not in(select nodeid from @tmpAIC) ' ...
- MyBatis 入门到精通(三) 高级结果映射
MyBatis的创建基于这样一个思想:数据库并不是您想怎样就怎样的.虽然我们希望所有的数据库遵守第三范式或BCNF(修正的第三范式),但它们不是.如果有一个数据库能够完美映射到所有应用程序,也将是非常 ...
- TortoiseHg简单的入门使用说明
参考资料: 互普的 TortoiseHg使用说明_百度文库 Mercurial(Hg)基本操作 - Tim Gong - 博客园 Mercurial与TortoiseHg使用入门教程(转) - mee ...