9du interactive community it famous enterprises recruitment on-board examination warm-up competition

Source: Internet
Author: User

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

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.