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. c++第一章1.6

    测试已完成(bingo)     1 [单选题] 下面代码能够实现交换操作的函数有(       )   A. swap(int a,int b) { int t=a;a=b;b=t;} B. swa ...

  2. golang bufio.NewScarme

    // dup1 输出标准输入中出现次数大于1的行,前面是次数 package main import ( "bufio" "fmt" "os" ...

  3. 干货来啦。Flask框架看这一篇就够了,关注不迷路,Jeff带你看源码。开发技术时时更新

    目录 一.初识Flask 1.1 什么是flask? 1.2 为什么要有flask? 二.Flask快速启动 三.Flask四剑客 三.flask的配置文件 可以配置的属性 四.flask路由 4.1 ...

  4. 创建和存储 cookie

    在这个例子中我们要创建一个存储访问者名字的 cookie.当访问者首次访问网站时,他们会被要求填写姓名.名字会存储于 cookie 中.当访问者再次访问网站时,他们就会收到欢迎词. 首先,我们会创建一 ...

  5. File判断功能(新手)

    //导入的一个类.import java.io.File;/* File判断功能*///创建的一个类.public class zylx3 { //公共静态的主方法. public static vo ...

  6. 如何用 Blazor 实现 Ant Design 组件库

    本文主要分享我创建 Ant Design of Blazor 项目的心路历程,已经文末有一个 Blazor 线上分享预告. Blazor WebAssembly 来了! Blazor 这个新推出的前端 ...

  7. ThinkPHP5.0 漏洞测试

    ThinkPHP5.0 漏洞测试 自从ThinkPHP发布漏洞补丁以来,服务器不知道多少次受到了批量扫描漏洞来抓取肉鸡的请求 虽然官方早已发布补丁,还是想试一下TP漏洞,测试两个漏洞 一.全版本执行漏 ...

  8. Django路由层与视图层、pycharm虚拟环境

    一. Django路由层 路由层即对应项目文件下的urls.py文件.实际上每个APP中也可以有自己的urls.py路由层.templates文件夹及static文件夹.Django支持这么做,也为实 ...

  9. [AI开发]零代码公式让你明白神经网络的输入输出

    这篇文章的标题比较奇怪,网上可能很少类似专门介绍神经网络的输入输出相关文章.在我实际工作和学习过程中,发现很有必要对神经网络的输入和输出做一个比较全面地介绍.跟之前博客一样,本篇文章不会出现相关代码或 ...

  10. 基于KNN的发票识别

    项目概况: 有一个PDF文件,里面的每页都是一张发票,把每页的发票单独存为一个PDF并用该发票的的发票号码进行文件的命名,发票号码需要OCR识别,即识别下图中红色方块的内容. 一:拆分PDF 现有一个 ...