HDU 4884 TIANKENG’s rice shop(模拟)——BestCoder Round #2
来源:互联网 发布:edius for mac 编辑:程序博客网 时间:2024/05/17 02:01
TIANKENG’s rice shop
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)
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
08:0209:0108:0508:1008:1008:0508:10
出题人的解题思路:
模拟题。当顾客来的时候,天坑如果不在炒饭,那么就给这个顾客炒饭。如果没有顾客到来,那么天坑会一直等待顾客到来,空闲的时候不会炒饭。如果在做的时候来客人需要相同的炒饭那么不会帮这人炒。题意:有m个顾客来店里买炒饭,给你每个顾客到达店里的时间、想要买的炒饭的种类以及数量,问每个顾客尽早离开的时间。
有以下条件需要满足:①顾客先到先服务;②若开始制作种类i的炒饭时,等待的顾客中多人选种类i的可以同时得到满足;③一次制作炒饭最多k碗,每次炒会炒尽可能多的份数,但不会有多余的留着备用;④顾客信息是按时间先后顺序给出的。还有一点要注意的是:每次制作炒饭的那段时间是不接单的。
此题一看就是模拟题,思路简单,但是要考虑的细节较多
举个例子,比如每次可以炒5份,每次5分钟。(即k=5,t=5)
第一个顾客08:00进来,点了2份A,
第二个顾客08:04进来,点了3份A。
在08:00开始炒的话,由于这个时候第二个顾客还没进来,所以就只炒2份,第一个顾客在08:05离开,这时才炒第二个的3份,所以第二个离开时间是08:10。
同样是每次可以炒5份,每次5分钟。
第一个顾客08:00进来,点了6份A,
第二个顾客08:01进来,点了5份B,
第三个顾客08:02进来,点了4份A。
同样地,先炒5份给第一个,还差一份,这是已经是08:05了,第三个顾客也进来了,所以这时直接炒5份A(因为会尽可能多地炒),08:10第一个和第三个可以同时离开。接着才炒第二个的。
另外需要注意的一点是顾客到达店里的时间必定是同一天的,即不会出现比如前一个顾客到达时间为23:59,后一个顾客到达时间为00:04,但是顾客离开店的时间未必是同一天,所以最终还需要对时间做点处理
放上两组数据以供参考
Input
100
3 5 4 6
23:50 1 4
23:51 2 1
23:52 3 1
23:53 2 1
23:54 3 3
23:56 2 2
Output
23:55
00:00
00:05
00:00
00:05
00:10
Input
100
3 5 4 3
23:50 1 5
23:52 2 7
23:58 2 1
Output
00:00
00:10
00:10
#pragma comment(linker, "/STACK:1024000000,1024000000")#include<stdio.h>#include<string.h>#include<stdlib.h>#include<queue>#include<math.h>#include<vector>#include<map>#include<set>#include<stdlib.h>#include<cmath>#include<string>#include<algorithm>#include<iostream>#define exp 1e-10using namespace std;const int N = 1005;const int inf = 1000000000;const int mod = 1000000007;struct person{ int t,id,num,ans;}s[N];int main(){ int T,n,t,k,m,i,j,hh,mm,f=0,c,K,tem; scanf("%d",&T); while(T--) { if(f++) puts(""); scanf("%d%d%d%d",&n,&t,&k,&m); for(c=i=0;i<m;i++) { scanf("%d:%d%d%d",&hh,&mm,&s[i].id,&s[i].num); s[i].t=hh*60+mm; s[i].ans=-1; } for(c=s[0].t,i=0;i<m;i++) { if(s[i].ans!=-1) continue; K=(s[i].num+k-1)/k; tem=max(c,s[i].t)+(K-1)*t; //printf("**%02d:%02d**\n",tem/60%24,tem%60); K*=k; for(j=i;j<m&&K&&s[j].t<=tem;j++) { if(s[j].id==s[i].id) { n=min(s[j].num,K); s[j].num-=n; K-=n; } if(s[j].num==0&&s[j].ans==-1) s[j].ans=tem+t; } c=tem+t; } for(i=0;i<m;i++) printf("%02d:%02d\n",s[i].ans/60%24,s[i].ans%60); } return 0;}菜鸟成长记
- HDU 4884 TIANKENG’s rice shop(模拟)——BestCoder Round #2
- hdu 4884 TIANKENG’s rice shop && BestCoder Round #2 1002
- HDU 4884 —— TIANKENG’s rice shop(模拟)
- HDU 4884 Bestcoder#2-1002 TIANKENG’s rice shop【模拟一发】
- hdu 4884 TIANKENG’s rice shop(模拟)
- hdu 4884 TIANKENG’s rice shop(模拟)
- HDU-4884-TIANKENG’s rice shop【模拟】
- hdu--4884--TIANKENG’s rice shop【模拟】
- HDU TIANKENG’s rice shop(模拟)
- [ACM] HDU 4884 TIANKENG’s rice shop (模拟)
- hdu 4884 TIANKENG’s rice shop(模拟)
- HDU 4884 TIANKENG’s rice shop (模拟)
- HDU-4884-TIANKENG’s rice shop
- HDU 4883 TIANKENG’s restaurant(排序或优先队列模拟)——BestCoder Round #2
- hdu4884 TIANKENG’s rice shop【模拟】
- HDU4884 TIANKENG’s rice shop【模拟】
- HDU4884 TIANKENG’s rice shop
- 【CUGBACM15级BC第二场 B】hdu 4884 TIANKENG’s rice shop
- 19 个 Android 开发工具
- vsftpd使用方法小结、Linux安装JDK出现“NoClassDefFoundError: /Object”的解决方案、ubuntu 12.04安装jdk
- java设计思想(2)
- iOS 在UILabel显示不同的字体和颜色
- 纪念我的第一次面试——华为研发类面试
- HDU 4884 TIANKENG’s rice shop(模拟)——BestCoder Round #2
- 事件——JavaScript高级程序设计笔记(10)
- BPM那些事儿——开源BPM引擎
- 使用自定义聚集函数来实现分组合并字符串
- nginx学习笔记
- Android中ActivityManager(AM)的方法解释和几个使用场景介绍
- 设计模式学习之--单例模式
- cocos2d js 使用 cocos studio 生成的合图
- HDU 3016 Man Down(线段树区间单点查询+DP)