Http://ac.jobdu.com/problem.php? PID = 1326 waiting in line
// Simple simulation question # include <iostream> # include <cstdio> using namespace STD; # include <memory. h> int PT [1001], leave [1001], start [21]; int n, m, K, Q; inline bool scan_d (Int & num) // This is the key to acceleration. {char in; bool isn = false; In = getchar (); If (in = EOF) return false; while (in! = '-' & (In <'0' | in> '9') in = getchar (); If (in = '-') {isn = true; num = 0;} else num = In-'0'; while (in = getchar (), in> = '0' & in <= '9') {num * = 10, num + = In-'0';} If (ISN) num =-num; return true;} void solve () {int I, j, index, T, P, Count = K; int num [21], window [21] [13]; memset (START, 0, sizeof (start); memset (Num, 0, sizeof (Num); j = Index = 1; for (I = 1; I <= N * M & I <= K; ++ I) // At the beginning, N windows are empty, the customer selects the shortest window of the team in sequence {window [J] [Index] = I; num [J] ++; J ++; If (j> N) {j = 1; ++ index ;}} J = I; // At the beginning, N windows have been filled with T = 0; while (T <= 540) {++ t; for (I = 1; I <= N; ++ I) {If (Num [I]> 0 & PT [window [I] [1] = T-start [I]) {leave [window [I] [1] = T; start [I] = T; -- count; // a user leaves for (P = 2; P <= num [I]; ++ p) window [I] [P-1] = Window [I] [p]; // after the first user of each window leaves, subsequent customers move forward in sequence -- num [I]; If (j <= k) // when there are still waiting customers, add another {window [I] [P-1] = J; ++ num [I]; ++ J ;}// if} // forif (! Count) // exit break directly when all customers are finished;} int main (void) {int I, J; while (scanf ("% d", & N, & M, & K, & Q )! = EOF) {memset (leave, 1, sizeof (leave); for (I = 1; I <= K; ++ I) scan_d (PT [I]); solve (); for (I = 0; I <q; ++ I) {scan_d (j); If (leave [J]> 540) puts ("sorry "); elseprintf ("% 02d: % 02d \ n", leave [J]/60 + 8, leave [J] % 60) ;}} return 0 ;}