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
 #include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;
struct person {
int arrive, start, time;
bool vip;
}tempperson;
struct tablenode {
int end = * , num;
bool vip;
};
bool cmp1(person a, person b) {
return a.arrive < b.arrive;
}
bool cmp2(person a, person b) {
return a.start < b.start;
}
vector<person> player;
vector<tablenode> table;
void alloctable(int personid, int tableid) {
if (player[personid].arrive <= table[tableid].end)
player[personid].start = table[tableid].end;
else
player[personid].start = player[personid].arrive;
table[tableid].end = player[personid].start + player[personid].time;
table[tableid].num++;
}
int findnextvip(int vipid) {
vipid++;
while (vipid < player.size() && player[vipid].vip == false) vipid++;
return vipid;
}
int main() {
int n, k, m, viptable;
scanf("%d", &n);
for (int i = ; i < n; i++) {
int h, m, s, temptime, flag;
scanf("%d:%d:%d %d %d", &h, &m, &s, &temptime, &flag);
tempperson.arrive = h * + m * + s;
tempperson.start = * ;
if (tempperson.arrive >= * ) continue;
tempperson.time = temptime <= ? temptime * : ;
tempperson.vip = ((flag == ) ? true : false);
player.push_back(tempperson);
}
scanf("%d%d", &k, &m);
table.resize(k + );
for (int i = ; i < m; i++) {
scanf("%d", &viptable);
table[viptable].vip = true;
}
sort(player.begin(), player.end(), cmp1);
int i = , vipid = -;
vipid = findnextvip(vipid);
while (i < player.size()) {
int index = -, minendtime = ;
for (int j = ; j <= k; j++) {
if (table[j].end < minendtime) {
minendtime = table[j].end;
index = j;
}
}
if (table[index].end >= * ) break;
if (player[i].vip == true && i < vipid) {
i++;
continue;
}
if (table[index].vip == true) {
if (player[i].vip == true) {
alloctable(i, index);
if (vipid == i) vipid = findnextvip(vipid);
i++;
}
else {
if (vipid < player.size() && player[vipid].arrive <= table[index].end) {
alloctable(vipid, index);
vipid = findnextvip(vipid);
}
else {
alloctable(i, index);
i++;
}
}
}
else {
if (player[i].vip == false) {
alloctable(i, index);
i++;
}
else {
int vipindex = -, minvipendtime = ;
for (int j = ; j <= k; j++) {
if (table[j].vip == true && table[j].end < minvipendtime) {
minvipendtime = table[j].end;
vipindex = j;
}
}
if (vipindex != - && player[i].arrive >= table[vipindex].end) {
alloctable(i, vipindex);
if (vipid == i) vipid = findnextvip(vipid);
i++;
}
else {
alloctable(i, index);
if (vipid == i) vipid = findnextvip(vipid);
i++;
}
}
}
}
sort(player.begin(), player.end(), cmp2);
for (i = ; i < player.size() && player[i].start < * ; i++) {
printf("%02d:%02d:%02d ", player[i].arrive / , player[i].arrive % / , player[i].arrive % );
printf("%02d:%02d:%02d ", player[i].start / , player[i].start % / , player[i].start % );
printf("%.0f\n", round((player[i].start - player[i].arrive) / 60.0));
}
for (int i = ; i <= k; i++) {
if (i != ) printf(" ");
printf("%d", table[i].num);
}
return ;
}

PAT甲级——A1026 Table Tennis的更多相关文章

  1. PAT甲级1026. Table Tennis

    PAT甲级1026. Table Tennis 题意: 乒乓球俱乐部有N张桌子供公众使用.表的编号从1到N.对于任何一对玩家,如果有一些表在到达时打开,它们将被分配给具有最小数字的可用表.如果所有的表 ...

  2. PAT 甲级 1026 Table Tennis(模拟)

    1026. Table Tennis (30) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue A table ...

  3. PAT 甲级 1026 Table Tennis (30 分)(坑点很多,逻辑较复杂,做了1天)

    1026 Table Tennis (30 分)   A table tennis club has N tables available to the public. The tables are ...

  4. PAT甲级1026 Table Tennis【模拟好题】

    题目:https://pintia.cn/problem-sets/994805342720868352/problems/994805472333250560 题意: 有k张乒乓球桌,有的是vip桌 ...

  5. PAT A1026 Table Tennis (30 分)——队列

    A table tennis club has N tables available to the public. The tables are numbered from 1 to N. For a ...

  6. PAT 1026 Table Tennis[比较难]

    1026 Table Tennis (30)(30 分) A table tennis club has N tables available to the public. The tables ar ...

  7. Pat(Advanced Level)Practice--1026(Table Tennis)

    Pat1026代码 题目描写叙述: A table tennis club has N tables available to the public. The tables are numbered ...

  8. PAT 1026. Table Tennis

    A table tennis club has N tables available to the public.  The tables are numbered from 1 to N.  For ...

  9. PAT 1026 Table Tennis (30)

    A table tennis club has N tables available to the public. The tables are numbered from 1 to N. For a ...

随机推荐

  1. 如何在select标签中使用a标签跳转页面

    1. 需求: 在select中想直接使用a标签跳转,错误想法 <select id=""> <option>choose one</option> ...

  2. 编译报错 :The method list(String, Object[]) is ambiguous for the type BaseHibernateDao<M,PK>

    原因:eclipse 的个bug,具体见http://stackoverflow.com/questions/10852923/method-is-ambiguous-for-the-type-but ...

  3. Java之RabbitMQ(二)多mq配置

    场景: springboot单项目,自身使用mq中间件处理一些业务需求,某些业务上又需要消费第三方mq消息,这时候需要我们单项目中配置多套mq,这时候,需要我们自定义多套mq相关连接工厂.模板.监听工 ...

  4. ERROR 1839 (HY000): @@GLOBAL.GTID_PURGED can only be set when @@GLOBAL.GTID_MODE = ON

    从cdb上dump一个库结构,准备与本地结构做对比(可以直接compare,但速度贼慢).使用dump脚本在本地创建的时候报错 -- 导出指定库的结构 shell> mysqldump -hxx ...

  5. 课程笔记-lisanke

    1.判断真需求假需求 真需求:所有人都需要的功能 假需求:只有自己需要的功能 2.找到目标用户 ①不要直接询问是否需要这个功能 ②旁敲侧击式提问:用户使用了什么方式?之前都是怎么做的? case:购物 ...

  6. 12-5-上下文this

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  7. bigcolorpicker 颜色拾取器插件——例

    参考:http://bigui4.sinaapp.com/picker/colorpicker.html 效果: html: <!DOCTYPE html> <html> &l ...

  8. webpack打包出错分析

    Module not found: Error: Can't resolve 'bundle.js' in 更改打包命令 webpack run1.js  -o bundle.js

  9. webpack 清理旧打包资源插件

    当我们修改带hash的文件并进行打包时,每打包一次就会生成一个新的文件,而旧的文件并 没有删除.为了解决这种情况,我们可以使用clean-webpack-plugin 在打包之前将文件先清除,之后再打 ...

  10. 深入浅出 Java Concurrency (35): 线程池 part 8 线程池的实现及原理 (3)[转]

    线程池任务执行结果 这一节来探讨下线程池中任务执行的结果以及如何阻塞线程.取消任务等等. 1 package info.imxylz.study.concurrency.future;2 3 publ ...