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代码:(有参考别人的)
 #include<cstdio>
#include<cstring>
#include<algorithm>
#include<cstdlib>
using namespace std;
const int N = ;
const int lim = *;
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/, time%);
}
int main(){
scanf("%d", &T);
while(T--){
scanf("%d %d %d %d", &n, &t, &k, &m);
memset(type,,sizeof(type));
int hh, mm, a, b;
int cur = ;
for(int i=; i<m; i++){
scanf("%d:%d %d %d", &hh, &mm, &a, &b);
hh = hh*+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-)/k + ;//做他的饭需要的总时间
cur = max(cur, hh) + t*x;
print(cur);
type[a] = x * k - b;//类型剩余量
last[a] = cur - t;//做最后一轮饭的开始时间
}
if(T) puts("");
}
return ;
}

HDOJ 4884 & BestCoder#2 1002的更多相关文章

  1. Bestcoder#5 1002

    Bestcoder#5 1002 Poor MitsuiTime Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (J ...

  2. [HDOJ 5212] [BestCoder Round#39] Code 【0.0】

    题目链接:HDOJ - 5212 题目分析 首先的思路是,考虑每个数对最终答案的贡献. 那么我们就要求出:对于每个数,以它为 gcd 的数对有多少对. 显然,对于一个数 x ,以它为 gcd 的两个数 ...

  3. bestcoder#23 1002 Sequence II 树状数组+DP

    Sequence II Time Limit: 5000/2500 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total ...

  4. 暴力+降复杂度 BestCoder Round #39 1002 Mutiple

    题目传送门 /* 设一个b[]来保存每一个a[]的质因数的id,从后往前每一次更新质因数的id, 若没有,默认加0,nlogn复杂度: 我用暴力竟然水过去了:) */ #include <cst ...

  5. DFS ZOJ 1002/HDOJ 1045 Fire Net

    题目传送门 /* 题意:在一个矩阵里放炮台,满足行列最多只有一个炮台,除非有墙(X)相隔,问最多能放多少个炮台 搜索(DFS):数据小,4 * 4可以用DFS,从(0,0)开始出发,往(n-1,n-1 ...

  6. 矩阵快速幂---BestCoder Round#8 1002

    当要求递推数列的第n项且n很大时,怎么快速求得第n项呢?可以用矩阵快速幂来加速计算.我们可以用矩阵来表示数列递推公式比如fibonacci数列 可以表示为 [f(n)   f(n-1)] = [f(n ...

  7. BestCoder #47 1001&amp;&amp;1002

    [比赛链接]cid=608">clikc here~~ ps:真是wuyu~~做了两小时.A出两道题,最后由于没加longlong所有被别人hack掉!,最后竟然不知道hack别人不成 ...

  8. BestCoder Round #92 1002 Count the Sheep —— 枚举+技巧

    题目链接:http://bestcoder.hdu.edu.cn/contests/contest_showproblem.php?cid=748&pid=1002 题解: 做题的时候只是想到 ...

  9. 贪心/二分查找 BestCoder Round #43 1002 pog loves szh II

    题目传送门 /* 贪心/二分查找:首先对ai%=p,然后sort,这样的话就有序能使用二分查找.贪心的思想是每次找到一个aj使得和为p-1(如果有的话) 当然有可能两个数和超过p,那么an的值最优,每 ...

随机推荐

  1. example of log4cpp properties configuration

    log 的优先级别解读,参阅源码 log4cpp-0.3.5rc3/include/log4cpp/Priority.hh 由高到低 EMERGFATALALERTCRITERRORWARNNOTIC ...

  2. OpenShift蓝绿及灰度部署

    内容转自https://blog.csdn.net/jj_tyro/article/details/80136316, 并不断补充,感谢作者. 1.蓝绿部署 蓝绿部署实现的是全流量切换,适合于在测试完 ...

  3. Log4net的一点改进

    昨天把log4net更新了一下,发现从NUGET上安装log4net后,使用方式简化了许多.以前我在文章<log4net使用简介>中介绍过,使用log4net需要有两步前期准备工作: 在使 ...

  4. XSS之浪潮已经来临

    前些天和Roy厉在微博上聊到微信公众账号,我说我在辛苦运营“网站安全中心”这个账号呢,他说我这账号粉丝少是少了点,不过用户定位精确,我说我不希望精确,因为我在尽可能写科普,科普需要传播. Roy厉说过 ...

  5. json字符串跟objective-c模型的相互转换

    在当今这样一个各种openapi开放的年代,在熟悉的语言下面找到一款得心应手的将json字符串转换成模型的库可以说是十分必要的,在NET平台下,我们有Newtonsoft.Json这个库使用,那么在i ...

  6. ​Mac触控板常用的手势操作

    ​Mac触控板常用的手势操作 学习了:http://topbook.cc/archives/151   一个手指直接点击,类似Windows中鼠标左键功能,同时在苹果Safari等浏览器中,这个手势还 ...

  7. DirectX游戏开发——从一个小游戏開始

    本系列文章由birdlove1987编写,转载请注明出处. 文章链接: http://blog.csdn.net/zhurui_idea/article/details/26364129 写在前面:自 ...

  8. 使用JTextArea示例

    相对于JLabel显示提示文字,JTextArea有一个先天优势:文字可以拷贝出来.经过下面设置它也能在外观上和JLabel一致. 代码如下: JTextArea txtArea=new JTextA ...

  9. java中的初始化块

    public class Person { int a=6;//声明实例变量制定默认值,也可以认为是对象的初始化代码,执行顺序与源代码中的排列顺序相同 { System.out.println(&qu ...

  10. 【大盛】全网首发HTC One/M7 最新本地化TrickDroid9.0/固件升级/永久root/高级,快速设置/稳定,流畅经典ROM

    了解更多请关注:点击打开链接 ROM版本 HTC One/M7_TrickDroid9.0.0 ROM作者 雪狼团队-大盛   http://weibo.com/DaShengdd Android版本 ...