Hdu4884tiankeng's rice shop (simulation)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.