1026 Table Tennis (30鍒?(妯℃嫙)
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了1026 Table Tennis (30鍒?(妯℃嫙)相关的知识,希望对你有一定的参考价值。
鏍囩锛?a href='http://www.mamicode.com/so/1/tab' title='tab'>tab
tar player sig oss element layout logical --1026 Table Tennis (30鍒?
A table tennis club has N tables available to the public. The tables are numbered from 1 to N. For any pair of players, if there are some tables open when they arrive, they will be assigned to the available table with the smallest number. If all the tables are occupied, they will have to wait in a queue. It is assumed that every pair of players can play for at most 2 hours.
Your job is to count for everyone in queue their waiting time, and for each table the number of players it has served for the day.
One thing that makes this procedure a bit complicated is that the club reserves some tables for their VIP members. When a VIP table is open, the first VIP pair in the queue will have the privilege to take it. However, if there is no VIP in the queue, the next pair of players can take it. On the other hand, if when it is the turn of a VIP pair, yet no VIP table is available, they can be assigned as any ordinary players.
Input Specification:
Each input file contains one test case. For each case, the first line contains an integer N
(≤10000) - the total number of pairs of players. Then N
lines follow, each contains 2 times and a VIP tag: HH:MM:SS
- the arriving time, P
- the playing time in minutes of a pair of players, and tag
- which is 1 if they hold a VIP card, or 0 if not. It is guaranteed that the arriving time is between 08:00:00 and 21:00:00 while the club is open. It is assumed that no two customers arrives at the same time. Following the players鈥?info, there are 2 positive integers: K
(≤100) - the number of tables, and M
(< K) - the number of VIP tables. The last line contains M
table numbers.
Output Specification:
For each test case, first print the arriving time, serving time and the waiting time for each pair of players in the format shown by the sample. Then print in a line the number of players served by each table. Notice that the output must be listed in chronological order of the serving time. The waiting time must be rounded up to an integer minute(s). If one cannot get a table before the closing time, their information must NOT be printed.
Sample Input:
9
20:52:00 10 0
08:00:00 20 0
08:02:00 30 0
20:51:00 10 0
08:10:00 5 0
08:12:00 10 1
20:50:00 10 0
08:01:30 15 1
20:53:00 10 1
3 1
2
Sample Output:
08:00:00 08:00:00 0
08:01:30 08:01:30 0
08:02:00 08:02:00 0
08:12:00 08:16:30 5
08:10:00 08:20:00 10
20:50:00 20:50:00 0
20:51:00 20:51:00 0
20:52:00 20:52:00 0
3 3 2
浣犱笉鍋氳繖涓浣犻兘涓嶇煡閬撹嚜宸辨湁澶氳彍(杩欏彞璇濈尞缁欐垜鑷繁)銆?br />
璇翠竴涓嬫垜璁や负鏈€鍧戠殑涓€涓偣鍚с€?br />
濡傛灉vip閫夋墜鏉ヤ簡锛岄偅涔堜粬閫夌紪鍙锋渶灏忕殑鍙互浣跨敤鐨剉ip妗屽瓙锛屾病鏈夌殑璇濆氨鐢ㄦ櫘閫氭瀛愩€?br />棰樼洰璇寸殑鏄疧n the other hand, if when it is the turn of a VIP pair, yet no VIP table is available, they can be assigned as any ordinary players.
涔熷氨鏄濡傛灉涓€涓獀ip鏉ヤ簡锛屼絾鏄鏃舵病鏈夊彲鐢ㄧ殑VIP妗屽瓙锛岄偅涔堜粬浠墠褰撲綔鏅€氱敤鎴峰鐞嗐€備篃灏辨槸璇村鏋滃瓨鍦╲ip妗屽瓙鍙敤锛岄偅浠栦滑涓嶇敤鏅€氭瀛愶紝鐢╲ip妗屽瓙銆?br />
鍓╀笅鐨勯兘鏄垜鑷繁鑿滃惂銆傘€傘€?br />
鑿滃埌鍝簡锛?br />
鍙兘鏄竴涓猰ap鐨刡egin琚垜erase浜嗭紝鐒惰€屾垜杩樼户缁湪鍙︿竴涓猰ap閲岄潰鎵捐繖涓猰ap鐨刡egin鍚с€備娇寰楁牱渚?杩囦笉浜嗐€傘€傘€傘€?br />
1 #include <iostream> 2 #include <string> 3 #include <map> 4 #include <vector> 5 #include <algorithm> 6 #include <sstream> 7 using namespace std; 8 9 struct A { 10 string arr, serve; 11 int wait_time; 12 }; 13 14 struct B { 15 int arr_time, last_time; 16 }; 17 18 map <string, B> mp, mp_vip; 19 vector <int> vec(100 + 5), num(100 + 5); 20 vector <bool> table_vip(100 + 5); 21 vector <A> ans; 22 23 int get_time(string time) { 24 char c; 25 int h, m, s; 26 stringstream ss; 27 ss << time; 28 ss >> h >> c >> m >> c >> s; 29 return h * 3600 + m * 60 + s; 30 } 31 32 string get_serve(int time) { 33 string ss; 34 int h, m, s; 35 h = time / 3600; 36 m = (time % 3600) / 60; 37 s = (time % 3600) % 60; 38 if(h < 10) ss += "0"; 39 ss += to_string(h); 40 ss += ":"; 41 if(m < 10) ss += "0"; 42 ss += to_string(m); 43 ss += ":"; 44 if(s < 10) ss += "0"; 45 ss += to_string(s); 46 return ss; 47 } 48 49 int main() { 50 string time; 51 int n, k, m, last_time, is_vip, arr_time; 52 cin >> n; 53 while(n --) { 54 cin >> time >> last_time >> is_vip; 55 arr_time = get_time(time); 56 if(last_time > 120) last_time = 120; 57 mp[time] = B{arr_time, last_time}; 58 if(is_vip) { 59 mp_vip[time] = B{arr_time, last_time}; 60 } 61 } 62 cin >> k >> m; 63 for(int i = 1; i <= k; i ++) { 64 vec[i] = 8 * 3600; 65 table_vip[i] = false; 66 num[i] = 0; 67 } 68 while(m --) { 69 cin >> is_vip; 70 table_vip[is_vip] = true; 71 } 72 map <string, B> :: iterator it; 73 while(true) { 74 if(mp.empty() || mp.begin() -> first >= "21:00:00") break; 75 int min_time = *min_element(vec.begin() + 1, vec.begin() + k + 1), pos; 76 for(int i = 1; i <= k; i ++) { 77 if(vec[i] == min_time) { 78 pos = i; 79 break; 80 } 81 } 82 if(vec[pos] >= 21 * 3600) break; 83 string serve; 84 if(table_vip[pos] && !mp_vip.empty() && mp_vip.begin() -> second.arr_time <= vec[pos]) { 85 num[pos] ++; 86 serve = get_serve(vec[pos]); 87 ans.push_back(A{mp_vip.begin() -> first, serve, (vec[pos] - mp_vip.begin() -> second.arr_time + 30) / 60}); 88 vec[pos] += 60 * mp_vip.begin() -> second.last_time; 89 it = mp.find(mp_vip.begin() -> first); 90 if(it != mp.end()) { 91 mp.erase(it); 92 } 93 mp_vip.erase(mp_vip.begin()); 94 } else { 95 it = mp_vip.find(mp.begin() -> first); 96 int min_vip = 21 * 3600, poss; 97 for(int i = 1; i <= k; i ++) { 98 if(vec[i] < min_vip && table_vip[i]) { 99 poss = i; 100 min_vip = vec[i]; 101 } 102 } 103 if(it != mp_vip.end() && min_vip <= it -> second.arr_time && it -> second.arr_time <= 21 * 3600) { 104 num[poss] ++; 105 serve = get_serve(it -> second.arr_time); 106 ans.push_back(A{it -> first, serve, 0}); 107 vec[poss] = it -> second.arr_time + 60 * it -> second.last_time; 108 mp_vip.erase(it); 109 mp.erase(mp.begin()); 110 } else { 111 num[pos] ++; 112 serve = get_serve(max(vec[pos], mp.begin() -> second.arr_time)); 113 ans.push_back(A{mp.begin() -> first, serve, vec[pos] > mp.begin() -> second.arr_time ? ((vec[pos] - mp.begin() -> second.arr_time) + 30) / 60 : 0 }); 114 vec[pos] = max(vec[pos], mp.begin() -> second.arr_time) + 60 * mp.begin() -> second.last_time; 115 mp.erase(mp.begin()); 116 if(it != mp_vip.end()) {//杩欓噷閿欎簡娌$湅鍑烘潵 117 mp_vip.erase(it); 118 } 119 } 120 } 121 } 122 for(int i = 0; i < ans.size(); i ++) { 123 cout << ans[i].arr << 鈥?/span> 鈥?/span> << ans[i].serve << 鈥?/span> 鈥?/span> << ans[i].wait_time << endl; 124 } 125 for(int i = 1; i <= k; i ++) { 126 if(i ^ 1) cout << 鈥?/span> 鈥?/span>; 127 cout << num[i]; 128 } 129 cout << endl; 130 return 0; 131 }
以上是关于1026 Table Tennis (30鍒?(妯℃嫙)的主要内容,如果未能解决你的问题,请参考以下文章
浙大 PAT Advanced level 1026. Table Tennis (30)
1026 Table Tennis (30 分) 未完成难度: 难 / 知识点: 模拟