Question: hdu4884tiankeng's rice shop (simulation)
A restaurant buys fried rice, provides you with the time and quantity of fried rice to be bought, and knows the highest score and time for one fried rice, ask the earliest departure time of these guests. Note: during the time of each fried rice meal, the ticket is not received.
Solution: simulation. There is no input data such as And, but the output may take another day. Then it is simulated. A disgusting question. For more information, see the comments.
Code:
# Include <cstdio> # include <cstring> # include <algorithm> using namespace STD; const int n = 1005; int N, T, K, M; int SUMT; struct Cus {int t; // The time when you enter the store int K; // The type of fried rice int num; // The number of int ans; // The time when you leave} C [N]; int main () {int t; int H, M; scanf ("% d", & T); While (t --) {scanf ("% d", & N, & T, & K, & M); For (INT I = 0; I <m; I ++) {scanf ("% d: % d", & H, & M, & C [I]. k, & C [I]. num); C [I]. T = H * 60 + m; // calculate by minute c [I]. ans =-1;} SUMT = C [0]. t; for (INT I = 0; I <m; I ++) {If (C [I]. ans! =-1) continue; int K = (C [I]. num + k-1)/K; // satisfy this guest and stir up as many fried rice as possible int have = K * k; int TMP = max (SUMT, C [I]. t) + (k-1) * t; // time of the last fried rice meal or time of the next meal for (Int J = I; j <m; j ++) {// if the guests at the backend have the same fried rice and come not later than the last fried rice time, they can give the remaining fried rice to the guest, the rest will be said later. If (C [J]. T> TMP |! Have) break; If (C [J]. k = C [I]. k) {int Mm = min (C [J]. num, have); C [J]. num-= mm; Have-= mm;} If (C [J]. num = 0 & C [J]. ans =-1) C [J]. ans = TMP + T;} SUMT = TMP + T;} For (INT I = 0; I <m; I ++) printf ("% 02d: % 02d \ n ", (C [I]. ANS/60) % 24, C [I]. ans % 60); // note that if (t) printf ("\ n");} return 0 ;}
Hdu4884tiankeng's rice shop (simulation)