1026 Table Tennis
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.
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.
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.
- 10
- 20:52:00 10 0
- 08:00:00 20 0
- 08:02:00 30 0
- 20:51:00 10 0
- 08:10:00 30 0
- 08:12:00 10 1
- 20:40:00 13 0
- 08:01:30 15 1
- 20:53:00 10 1
- 20:54:00 10 0
- 3 1
- 2
- 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:40:00 20:40:00 0
- 20:51:00 20:51:00 0
- 20:52:00 20:52:00 0
- 20:53:00 20:53:00 0
- 4 3 2
总结:这种题现在的实力还写不出来,还得加油,多写写题目
- #include
- #include
- #include
- #include
- using namespace std;
- int n, m, k, H, M, S, t, table, vtable, cnt, now, nowt, T[100000], V[100000], num[10001], AnsI[10001], AnsO[10001], vip[10001];
- map<int, int> Table;
- queue<int> Wait, vWait;
- int main() {
- scanf("%d", &n);
- for (int i = 0; i < n; i++) {
- scanf("%d:%d:%d", &H, &M, &S);
- t = H * 3600 + M * 60 + S;
- scanf("%d %d", &T[t], &V[t]);
- T[t] = min(T[t], 120) * 60;//因为最多只能玩两个小时,如果超出两个小时,则取两个小时
- }
- scanf("%d %d", &m, &k);
- for (int i = 0; i < k; i++) {
- scanf("%d", &t);
- vip[t] = 1;//vip桌
- }
- for (int Time = 28800; Time < 75600; Time++, table = vtable = now = 0) {
- if (T[Time] && V[Time]) vWait.push(Time);//当前时刻有人来且这个人是vip,加入vip队列中
- else if (T[Time]) Wait.push(Time);//当前时刻有人来,但这个人不是vip,加入普通人队列中
- for (int i = 1; i <= m; i++) {//遍历每一张桌子
- if (Table[i] > 0) Table[i]--;//当前桌子有人玩,剩余时间秒数-1
- if (Table[i] == 0 && vip[i] && vtable == 0) vtable = i;//当前桌子没有玩,且是vip桌,且在此桌之前的桌子vip桌都是有人的,vtable记录当前可以的编号最小的vip桌子
- if (Table[i] == 0 && table == 0) table = i;//当前编号桌子没有人,且在这个编号桌子之前的桌子都是有人的,table记录当前未使用的最小编号的桌子
- }
- if (!vWait.empty() && (table || vtable)) {
- now = vWait.front();//将队列中第一个vip叫出来
- nowt = vtable;//记录当前可用的最小编号的桌子
- if (vtable != 0) vWait.pop();//如果有vip桌子的话,那就让那个人去打
- else {//否则让他去打普通的桌子
- nowt = table;
- //如果当前非vip在vip排队之前,那么让队列前面的人去打
- if (!Wait.empty() && Wait.front() < vWait.front()) {
- now = Wait.front();
- Wait.pop();
- } else vWait.pop();//否则让vip去打
- }
- } else if (!Wait.empty() && table) {//没有vip,且有桌子
- nowt = table;
- now = Wait.front();
- Wait.pop();
- }
- if (now == 0) continue;//如果此时刻没有人来,且没有在队列当中
- Table[nowt] = T[now];//更新结束时间
- AnsI[cnt] = now;//用户到达时间
- AnsO[cnt++] = Time;// 用户开始玩的时间,这两个相减可以算出用户等待时间
- num[nowt]++;//表示当前的桌子被用过一次,+1
- }
- for (int i = 0; i < cnt; i++)
- printf("%02d:%02d:%02d %02d:%02d:%02d %d\n", AnsI[i] / 3600, AnsI[i] % 3600 / 60, AnsI[i] % 60, AnsO[i] / 3600, AnsO[i] % 3600 / 60, AnsO[i] % 60, (AnsO[i] - AnsI[i] + 30) / 60);
- for (int i = 1; i <= m; i++) {
- if (i != 1) printf(" ");
- printf("%d", num[i]);
- }
- return 0;
- }
好好学习,天天向上!
我要考研!