HDU4884 TIANKENG’s rice shop【模拟】

来源:互联网 发布:机械先驱知乎 编辑:程序博客网 时间:2024/05/16 18:31

TIANKENG’s rice shop

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


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
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
 

Source
BestCoder Round #2
 

Recommend
liuyiding   |   We have carefully selected several similar problems for you:  5609 5608 5607 5606 5605 
 



这题难倒是不难就是有个神坑,就是排队有可能排过夜的...(卧槽这谁想得到)。所以时间要取余24*60

#include <iostream>#include <cstdio>#include <cstring>using namespace std;struct node{int time;int depart;int id;int num;}customer[1000+10];int main(){int T;scanf("%d",&T);while(T--){memset(customer,0,sizeof customer);int n,t,k,m;scanf("%d%d%d%d",&n,&t,&k,&m);for(int i=0 ; i<m ; ++i){int hh,mm;scanf("%d:%d",&hh,&mm);customer[i].time=hh*60+mm;scanf("%d%d" , &customer[i].id , &customer[i].num);}int now=customer[0].time;for( int p=0 ; p<m ; ++p ){if(!customer[p].num)continue;//如果已经离开了就不用炒了 if(now<customer[p].time)now=customer[p].time;now+=customer[p].num/k*t;int left=k-customer[p].num%k;//最后一次还能顺带炒多少给下面的人 if(left!=k)//customer[p].num%k!=0{for(int i=p+1 ; i<m ; ++i)//历遍所有人 {//类型相同且已经到了 if(customer[i].id==customer[p].id && customer[i].time<=now){if(customer[i].num>left){customer[i].num-=left;break;}else{left-=customer[i].num;customer[i].num=0;customer[i].depart=now+t;if(left==0) break;}}//else break;}now+=t;//最后一次炒完}customer[p].depart=now;}for(int i=0 ; i<m ; ++i){customer[i].depart%=24*60;printf("%02d:%02d\n",customer[i].depart/60,customer[i].depart%60);}if(T)printf("\n");}return 0;}


0 0
原创粉丝点击