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 priviledge 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
某乒乓球场每天服务时间是8:00 -- 21:00,有·K个桌子(编号 1-K),其中M个为会员预留,某一天,有N个玩家要来打球,给出了他们的到达时间,玩耍时间,和他们是否是会员,要求,输出这些玩家的 到达时间 开始被服务时间 玩耍时间。输出每个桌子服务的人数。
需要注意的是:
21:00及之后到来的玩家无法被服务,这些玩家不用考虑;
由于排队等待导致21:00前还未能被服务的玩家也要在输出中排除;
每个乒乓球求桌子限制最多一次服务2个小时;
所有的输出顺序要按照玩家开始被服务时间的先后顺序。
vip玩家的服务优先级高于普通玩家。当没有会员来时,vip桌子也为普通用户服务。这个的具体理解我在思路中细说。
思路解析说实话这个题目难度不高,无非就是先来先服务,也就是所有玩家按照到达的先后顺序排序然后逐个处理,只不过vip可以" 插队 " 就导致分类讨论比较复杂一点。
框架步骤
创建结构体 Player 保存玩家的 到达时间、开始被服务时间、玩耍时间、是否是会员。
struct Player { // 到达时间,开始时间,玩耍时间 int arrive_time, start_time, play_time; bool isvip; // 是否是 vip };创建结构体 Table 保存每个桌子 何时结束当前服务、服务了几个人、是不是为vip预留。所有桌子刚开始都是8:00开始服务,所以 end_time 字段初始化为 8 * 3600。
struct Table { // 当前服务结束时间,已服务玩家个数 // 刚开始全是8:00开始服务 int end_time = club_open_time, serve_count; bool isvip; // 是否是为vip预留的桌子 };用vector保存玩家信息和桌子信息。
把所有时间都转换为以 00:00:00 开始的秒数进行处理。
逐个读入玩家的信息,对于到达时间在 21:00及之后的不予理睬。对于”合法“用户,如果玩耍时间超过两小时,将其值赋为7200s,将被开始服务时间初始化为 21:00,这样做的目的是,所有得到服务的玩家这个字段一定会被改变成小于 21:00 的时间,最终在输出时能很方便的过滤掉那些未被服务的玩家信息。
对所有玩家按照到达时间进行排序。
逐个处理”玩家“,分类四种讨论,我们下面单独拿出来说它。
处理完所有玩家,按照被服务的开始时间排序
输出结果(过率掉未被服务玩家)
第7步细说(对每个玩家的处理)
找到所有桌子中最早结束当前服务的桌子,序号为 index。
如果这个桌子当前服务的结束时间 >= 21 * 3600,那剩下的玩家都不用处理了,不可能被服务。否则再继续下面的过程。