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
题目分析:对于顾客先进行排序 然后分析第一个空闲的桌子是不是vip的情况
如果第一个空闲的桌子是vip,找到第一个vip会员进行讨论
如果第一个空闲的桌子不是vip,看队列中第一个队员是否为vip 若不是直接给他,若是vip 在所有桌子中找到vip桌子进行讨论
做这种题最最要的是分清楚情况 想的细一点对做题有帮助
 #define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<vector>
#include<queue>
#include<stack>
#include<algorithm>
#include<string>
#include<cmath>
using namespace std;
struct customer {
int arriveTime = ;
int startTime = ;
int playtime = ;
int tag = ;
};
struct table{
int time = * ;
int humans=;
int flag=;
};
vector<customer> Customer;
vector<table>Table;
bool compare(const customer& a, const customer& b)
{
return a.arriveTime < b.arriveTime;
}
bool cmp(const customer& a, const customer& b)
{
return a.startTime < b.startTime;
}
int findNextvipid(int vipid)
{
vipid++;
while (vipid < Customer.size() && Customer[vipid].tag != )vipid++;
return vipid;
}
void collect(int customerid, int tableid)
{
if (Customer[customerid].arriveTime < Table[tableid].time)
Customer[customerid].startTime = Table[tableid].time;
else
Customer[customerid].startTime = Customer[customerid].arriveTime;
Table[tableid].time = Customer[customerid].startTime + Customer[customerid].playtime;
Table[tableid].humans++;
}
int main()
{
int N, K, MV, MC, viptable;
cin >> N;
customer c;
for (int i = ; i < N; i++)
{
int hh, mm, ss;
scanf("%d:%d:%d %d %d", &hh,&mm,&ss,&(c.playtime),&(c.tag));
c.arriveTime = hh * + mm * + ss;
c.startTime = * ;
if (c.arriveTime >= * )continue;
c.playtime = (c.playtime < ) ? c.playtime * : ;
Customer.push_back(c);
}
sort(Customer.begin(), Customer.end(), compare);
cin >> K >> MV;
Table.resize(K + );
for (int i = ; i < MV; i++)
{
scanf("%d", &viptable);
Table[viptable].flag = ;
}
int i = , vipid = -;
vipid = findNextvipid(vipid);
while (i<Customer.size())
{
int index = -, minendtime = ;
for (int j = ; j <=K; j++)
{
if (minendtime > Table[j].time)
{
minendtime = Table[j].time;
index = j;
}
}
if (Table[index].time>= * )break;
if (Customer[i].tag == && i < vipid)
{
i++;
continue;
}
if (Table[index].flag == )
{
if (Customer[i].tag == )
{
collect(i, index);
if(vipid==i)vipid = findNextvipid(vipid);
i++;
}
else
{
if (vipid < Customer.size() && Customer[vipid].arriveTime <= Table[index].time)
{
collect(vipid, index);
vipid = findNextvipid(vipid);
}
else
{
collect(i, index);
i++;
}
}
}
else
{
if (Customer[i].tag != )
{
collect(i, index);
i++;
}
else
{
int vipindex = -, minviptime = ;
for (int j = ; j <= K; j++)
{
if (Table[j].flag == && Table[j].time < minviptime)
{
minviptime=Table[j].time;
vipindex = j;
}
}
if (vipindex != - && Customer[i].arriveTime >= Table[vipindex].time)
{
collect(i, vipindex);
if (i == vipid)vipid = findNextvipid(vipid);
i++;
}
else
{
collect(i, index);
if (i == vipid)vipid = findNextvipid(vipid);
i++;
}
}
}
}
sort(Customer.begin(), Customer.end(), cmp);
for (i = ; i < Customer.size() && Customer[i].startTime < * ; i++) {
printf("%02d:%02d:%02d ", Customer[i].arriveTime / , Customer[i].arriveTime% / , Customer[i].arriveTime % );
printf("%02d:%02d:%02d ", Customer[i].startTime / , Customer[i].startTime % / , Customer[i].startTime % );
printf("%.0f\n", round((Customer[i].startTime - Customer[i].arriveTime) / 60.0));
}
for (int i = ; i <= K; i++) {
if (i != ) printf(" ");
printf("%d", Table[i].humans);
}
}

1026 Table Tennis (30分)的更多相关文章

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

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

  2. 1026 Table Tennis (30分) 难度不高 + 逻辑复杂 +细节繁琐

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

  3. 【PAT甲级】1026 Table Tennis (30 分)(结构体排序,trick较多)

    题意: 输入一个正整数N(<=10000),表示客户(对)的大小,接着输入N行数据,每行包括一对顾客到场的时间,想要玩的时间,以及是否是VIP客户.接下来输入两个正整数K,M(K<=100 ...

  4. 1026 Table Tennis (30)(30 分)

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

  5. 1026. Table Tennis (30)

    题目如下: A table tennis club has N tables available to the public. The tables are numbered from 1 to N. ...

  6. 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 ...

  7. PAT (Advanced Level) 1026. Table Tennis (30)

    情况比较多的模拟题. 交了50发的样子才AC......AC之后我的天空星星都亮了. #include<iostream> #include<cstring> #include ...

  8. PAT 1026 Table Tennis[比较难]

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

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

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

随机推荐

  1. vue基础回顾 router

    vue-router 1. 底层原理 hash 或者h5 histroy(有兼容性) 2. 使用的时候Vue需要引入VueRouter Vue.use(VueRouter) //VueRouter 底 ...

  2. python从数据库取数据后写入excel 使用pandas.ExcelWriter设置单元格格式

    用python从数据库中取到数据后,写入excel中做成自动报表,ExcelWrite默认的格式一般来说都比较丑,但workbook提供可以设置自定义格式,简单记录个demo,供初次使用者参考. 一. ...

  3. celery订单定时回滚

    目录 订单回滚 控制执行(多少时间后执行) celery异步定时任务 订单回滚 用celery异步,定时任务.可以设置:如果下单15分钟后没有支付,则取消订单.做反向操作 控制执行(多少时间后执行) ...

  4. 《Linux环境进程间通信》系列文章链接

    深刻理解 Linux 进程间通信(IPC) http://www.ibm.com/developerworks/cn/linux/l-ipc/index.html Linux 环境进程间通信(一): ...

  5. (转)协议森林14 逆袭 (CIDR与NAT)

    协议森林14 逆袭 (CIDR与NAT) 作者:Vamei 出处:http://www.cnblogs.com/vamei 欢迎转载,也请保留这段声明.谢谢! IPv4由于最初的设计原因,长度只有32 ...

  6. Http报文和Request和Response的常用方法

    简述 它是HTTP应用程序之间发送的数据块.这些数据块以一些文本形式的元信息开头,这些信息描述了报文的内容及含义,后面跟着可选的数据部分.这些报文都是在客户端.服务器和代理之间流动. HTTP报文的流 ...

  7. Linux命令进阶篇-文件查看与查找

    上一篇的博客对于Linux如何在不同目录下跳转和查看目录下内容做出了总结,主要靠cd和ls,很常见也很实用.但是你看到目录下面那么多不同花花绿绿的文件,心里是不是痒痒,是不是想进去一探究竟,有办法! ...

  8. SpringMVC框架——常用注解

    @RequestMapping Spring MVC 通过 @RequestMapping 注解将请求与业务方法进行映射,在方法定义处,在类定义都可以添加该注解. 常用参数: 1.value:指定请求 ...

  9. Systematic comparison of strategies for the enrichment of lysosomes by data independent acquisition 通过DIA技术系统比较各溶酶体富集策略 (解读人:王欣然)

    文献名:Systematic comparison of strategies for the enrichment of lysosomes by data independent acquisit ...

  10. 深夜,我用python爬取了整个斗图网站,不服来斗

    QQ.微信斗图总是斗不过,索性直接来爬斗图网,我有整个网站的图,不服来斗. 废话不多说,选取的网站为斗图啦,我们先简单来看一下网站的结构 网页信息 从上面这张图我们可以看出,一页有多套图,这个时候我们 ...