Tiankeng's Restaurant
Time Limit: 2000/1000 MS (Java/Others)
Memory limit: 131072/65536 K (Java/Others)
Total submission (s): 0
Accepted submission (s): 0
Problem descriptionTiankeng manages a restaurant after graduating from zcmu, and tens of thousands of MERs come to have meal because of its delicious dishes. today N groups of MERs come to enjoy their meal, and there are Xi persons in the ith group in sum. assuming that each customer can own only one chair. now we know the arriving time STI and departure time EDI of each group. cocould you help tiankeng calcu Late the minimum chairs he needs to prepare so that every customer can take a seat when arriving the restaurant?
InputThe first line contains a positive integer T (t <= 100), standing for T test cases in all.
Each cases has a positive integer N (1 <= n <= 10000), which means N groups of customer. then following n lines, each line there is a positive integer XI (1 <= xi <= 100), referring to the sum of the number of the ith group people, and the arriving time STI and departure time EDI (the time format is hh: Mm, 0 <= hh <24, 0 <= mm <60 ), given that the arriving time must be earlier than the departure time.
Pay attention that when a group of people arrive at the restaurant as soon as a group of people leaves from the restaurant, then the arriving group can be arranged to take their seats if the seats are enough.
OutputFor each test case, output the minimum number of chair that tiankeng needs to prepare.
Sample Input226 09: 5926
Sample output116 problem solving: Post-order simulation + priority queue
1 # include <iostream> 2 # include <cstdio> 3 # include <cstring> 4 # include <cmath> 5 # include <algorithm> 6 # include <climits> 7 # include <vector> 8 # include <queue> 9 # include <cstdlib> 10 # include <string> 11 # include <set> 12 # define ll long long13 # define INF 0x3f3f3f14 using namespace STD; 15 struct node {16 int time, index; 17 Friend bool operator <(node X, Node B) {18 return X. time> B. time; 19} 20 }; 21 priority_queue <node> q; 22 struct P {23 int num, ary, lev; 24}; 25 p [10020]; 26 bool CMP (const P & X, const P & Y) {27 return (X. ary <Y. ary | X. ary = y. ary & X. ev <Y. ev); 28} 29 int main () {30 int T, I, j, N, K; 31 int H1, H2, M1, M2; 32 scanf ("% d", & T); 33 while (t --) {34 while (! Q. empty () Q. pop (); 35 scanf ("% d", & N); 36 for (I = 0; I <n; I ++) {37 scanf ("% d: % d", & K, & H1, & M1, & H2, & m2 ); 38 P [I]. ary = h1 * 60 + M1; 39 p [I]. ev = h2 * 60 + m2; 40 P [I]. num = K; 41} 42 sort (p, p + N, CMP); 43 int TM, ANS = 0, BA = 0; // The remaining Table 44 Q. push (node) {P [0]. ev, 0}); 45 ans = P [0]. num; 46 node TP; 47 for (I = 1; I <n; I ++) {48 TM = P [I]. ary; 49 If (P [I]. ary = P [I]. ev) continue; 50 TP = Q. top (); 51 Q. push (node ){ P [I]. lev, I}); 52 while (! Q. empty () & TP. time <= TM) {53 BA + = P [TP. index]. num; 54 Q. pop (); 55 TP = Q. top (); 56} // reclaim operation 57 if (P [I]. num> BA) {58 ans + = P [I]. num-BA; 59 BA = 0; 60} else ba-= P [I]. num; // assign 61} 62 printf ("% d \ n", ANS); 63} 64 return 0; 65}
View code