1026 Table Tennis (30分)
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
题目分析:对于顾客先进行排序 然后分析第一个空闲的桌子是不是vip的情况
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桌子进行讨论
做这种题最最要的是分清楚情况 想的细一点对做题有帮助
#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分)的更多相关文章
- PAT 甲级 1026 Table Tennis (30 分)(坑点很多,逻辑较复杂,做了1天)
1026 Table Tennis (30 分) A table tennis club has N tables available to the public. The tables are ...
- 1026 Table Tennis (30分) 难度不高 + 逻辑复杂 +细节繁琐
题目 A table tennis club has N tables available to the public. The tables are numbered from 1 to N. Fo ...
- 【PAT甲级】1026 Table Tennis (30 分)(结构体排序,trick较多)
题意: 输入一个正整数N(<=10000),表示客户(对)的大小,接着输入N行数据,每行包括一对顾客到场的时间,想要玩的时间,以及是否是VIP客户.接下来输入两个正整数K,M(K<=100 ...
- 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 ...
- 1026. Table Tennis (30)
题目如下: A table tennis club has N tables available to the public. The tables are numbered from 1 to N. ...
- 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 ...
- PAT (Advanced Level) 1026. Table Tennis (30)
情况比较多的模拟题. 交了50发的样子才AC......AC之后我的天空星星都亮了. #include<iostream> #include<cstring> #include ...
- PAT 1026 Table Tennis[比较难]
1026 Table Tennis (30)(30 分) A table tennis club has N tables available to the public. The tables ar ...
- PAT 甲级 1026 Table Tennis(模拟)
1026. Table Tennis (30) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue A table ...
随机推荐
- nsq 初学使用日记
win下更加直观一些,所以不使用liunx 第一步下载 nsq 下载地址 https://github.com/nsqio/nsq.git 使用git clone或者go get 下载下来 第二部 编 ...
- Keil MDK版兼容51系列单片机开发环境安装
一.安装源文件下载 百度网盘链接:https://pan.baidu.com/s/18tnjFgVat4q2hDSh7LAD8A 提取码: 2295 二.安装及破解 1.安装51的编辑器 双击安 ...
- Python 【绘制图及turtle库的使用】
前言 最近翻到一篇知乎,上面有不少用Python(大多是turtle库)绘制的树图,感觉很漂亮,整理了一下,挑了一些觉得不错的代码分享给大家(这些我都测试过,确实可以生成喔~赶快去试一下吧) one ...
- 【工具】Intel HLS工具
目前新版本的Quartus 软件 都自带有 HLS 工具,比如 18.1版本安装以后,HLS相关文件夹如下: HLS工具 也可以单独下载: https://www.intel.com/content ...
- 详解分页组件中查count总记录优化
1 背景 研究mybatis-plus(以下简称MBP),使用其分页功能时.发现了一个JsqlParserCountOptimize的分页优化处理类,官方对其未做详细介绍,网上也未找到分析该类逻辑的只 ...
- sessionStorage localStorage 和 cookie 之间的区别转
sessionStorage 和 localStorage 是HTML5 Web Storage API 提供的,可以方便的在web请求之间保存数据.有了本地数据,就可以避免数据在浏览器和服务器间不必 ...
- 【opencv系列02】OpenCV4.X图像读取与显示
一.读取图片 opencv中采用imread() 函数读取图像 imread(filename, flags=None) filename 图片的路径 flags 图像读取方式 ● c ...
- Zend Studio 13.6.1 汉化及安装方法详解
Zend Studio 13.6.1是一套专业开发人员使用的集成开发环境 (IDE),具备功能强大的专业编辑工具和调试工具,支持PHP语法加亮显示,支持语法自动填充功能,支持书签功能,支持语法自动缩排 ...
- vscode如何配置debug,python正则表达式如何匹配括号,关于python如何导入自定义模块
关于vscode如何配置debug的问题: 1.下载安装好python,并且配置好 环境变量 2.https://www.cnblogs.com/asce/p/11600904.html 3.严格按照 ...
- VS2019 C++动态链接库的创建使用(3) - 如何导出类
如何在动态链接库里导出一个类? ①在库头文件里增加一个类声明,class DLL1_API Point是将类内所有成员都导出,如果只导出某个成员函数,则只需在对应的成员函数前加DLL1_API即可: ...