1026 Table Tennis (30分)(模拟)

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


你不做这个题你都不知道自己有多菜(这句话献给我自己)。


说一下我认为最坑的一个点吧。

如果vip选手来了,那么他选编号最小的可以使用的vip桌子,没有的话就用普通桌子。
题目说的是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.
也就是说如果一个vip来了,但是此时没有可用的VIP桌子,那么他们才当作普通用户处理。也就是说如果存在vip桌子可用,那他们不用普通桌子,用vip桌子。


剩下的都是我自己菜吧。。。

菜到哪了?

可能是一个map的begin被我erase了,然而我还继续在另一个map里面找这个map的begin吧。使得样例7过不了。。。。



  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 << ' ' << ans[i].serve << ' ' << ans[i].wait_time << endl;
124     }
125     for(int i = 1; i <= k; i ++) {
126         if(i ^ 1) cout << ' ';
127         cout << num[i];
128     }
129     cout << endl;
130     return 0;
131 }
 

猜你喜欢

转载自www.cnblogs.com/bianjunting/p/13196815.html
今日推荐