Tiankeng ' s Rice shop
Problem Description
Tiankeng managers a pan fried rice shop. There is n kinds of fried rice numbered 1-n. Tiankeng would 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 is m customers coming to the shop, and we know the arriving time of each customer and the brand and N Umber of the fried rice they need. Could you tell Tiankeng the departure time of every customer respectively? Pay attention this TIANKNEG would serve the customer who comes earlier and he'll fry the rice as much as possible. Meanwhile, customers is 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) and referring to T test cases.
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 have a time (the time format is hh:mm, 0<=hh<=23, 0<=mm<=59) a ND-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's or more customers won't come to the shop at the same time, the arriving time of the customer wil L 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 the 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
Problem Solving Ideas:
This simulation problem is too pit ...
There are a total of n kinds of fried rice, each fried rice is spent t minutes, Fry once is the amount of k, each can only fry the same kind of fried rice, have m guests, give each guest arrival time, as well as the type and quantity of fried rice, ask each guest the earliest departure time.
At first, the third set of test data was not understood.
n=2 t=5 k=4 m=2
08:00 1 1
08:04 1 1
The first guest at 8 points to the first kind of fried rice 1 points, the second guest 8 point 04 of the time to the 1th kind of fried rice 1 parts, then directly fry 4 parts is not OK? Two guests are left 0:5, pit Ah, can not be so, the right should be so with practice, the first to be the first guests to the first kind of fried rice 1, then it will take 5 minutes to fry only 1, although this 5 minutes there is a second guest, but can not be fired, and so the first guest to go after, Let's get the second guest to Fry.
There is another situation, the back can be added to the front of the FRY
Or the previous data, but the guest's information should be
08:00 1 6
08:02 2 1
08:03 1 X
First guests, to 6, because a maximum of 4 parts at a time, so the first post-fry 4 parts, the time is 8 points 05, then the second and the third place are coming, just the third and the first to be the same, then the next time for the first guest fried rice (because the difference of 2 parts), You can also fry out for the third guest, if x=2, then the last time for the first guest fried rice, 2 copies to it, 2 to the third person can, two guests at the same time leave, if x<2, assuming 1, then the last time just fry 3 copies can be. If x>2, then fry out 2 points to the third guest to keep, to his time, then give him to fry X-2 copies is enough.
Write this problem, dizzy dizzy ...
Code:
#include <iostream> #include <stdio.h> #include <algorithm> #include <string.h> #include < stdlib.h> #include <cmath> #include <iomanip> #include <vector> #include <set> #include < map> #include <stack> #include <queue> #include <cctype>using namespace std; #define LL Long longconst int maxn=1002;//max species int n,t,k,m;//n is the number of species, T is the time of a fried rice, K is one can fry how many copies, M is have m guest bool done[maxn];struct customer{int h , M; int time; int kind; int num; int ans;} cus[maxn];void output (int t) {int h=t/60; h%=24; int m=t%60; if (h<=9) printf ("0%d:", h); else printf ("%d:", h); if (m<=9) printf ("0%d\n", m); else printf ("%d\n", m);} int main () {int t;scanf ("%d", &t); while (t--) {scanf ("%d%d%d%d", &n,&t,&k,&m); memset (done,0,sizeof (done)); for (int i=1;i<=m;i++) {scanf ("%d:%d%d%d", &cus[i].h,&cus[i].m,&cus[i].kind,&cUs[i].num); CUS[I].TIME=CUS[I].H*60+CUS[I].M; } int curtime=-1;//current time for (int i=1;i<=m;i++) {if (done[i]) continue; if (cus[i].time>=curtime) curtime=cus[i].time; int c= (cus[i].num)/k;//for the first I customers need to fry several times if (cus[i].num%k!=0) C + +; cout<< "tt" <<tt<<endl; cus[i].ans=curtime+c*t;//first customer departure time//int curt=curtime+cus[k].num/k*t; int curt=cus[i].ans-t;//for the first I customer the time of the last fried rice,//Because at this point to see whether the customer is the same as the current customer wants, go with "Fry out part" curtime=cus[i].a ns int left=c*k-cus[i].num;//The last time can be more than a part, such as 4 per Fry, the current customer to 10, then have to fry 3 times, the third fry can be fried 4 parts, then will be more than 2 parts done[i]=1; cout<< "KK" <<k<< "left" <<left<<endl; for (int j=i+1;j<=m;j++) {if (cus[j].time>curt) break; if (Cus[j].kind!=cus[i].kind) Continue if (left>=cus[j].num)//The current customer extra rice can be directly to the back of the required {//cout<< "Inininininin" <<endl; Cus[j].ans=cus[i].ans; Done[j]=1; Left-=cus[j].num; } else {cus[j].num-=left; left=0; Break }}//kindn[cus[k].kind]+=left; cout<<cus[k].kind<< "Sssssssss" <<left<<endl; } for (int i=1;i<=m;i++) output (Cus[i].ans); if (T) printf ("\ n"); } return 0;}
[ACM] HDU 4884 Tiankeng ' s rice Shop (analogue)