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 ...
随机推荐
- sonarqube配置全指南,集成阿里巴巴p3c规范
环境准备 内置数据库 Sonar安装成功后,默认内置H2数据库,用于记录单次的扫描结果,对同一个project重复扫码,会覆盖之前的扫描记录,所以H2 数据库只应用于测试,不可以用于生产环境,那如果你 ...
- 使用ajax提交登录
引入jquery-1.10.2.js或者jquery-1.10.2.min.js 页面 <h3>后台系统登录</h3> <form name="MyForm&q ...
- python学习基础知识
学习python前最好知道的知识点: python之父:Guido van Rossum python是一种面向对象语言 目前python最新的版本是3.8,python2已经逐渐淘汰 python的 ...
- 机器学习实用案例解析(1) 使用R语言
简介 统计学一直在研究如何从数据中得到可解释的东西,而机器学习则关注如何将数据变成一些实用的东西.对两者做出如下对比更有助于理解“机器学习”这个术语:机器学习研究的内容是教给计算机一些知识,再让计算机 ...
- 关于QThread使用锁死的探索
在学习使用QT5的时候,发现要使用多线程处理多任务,按照https://www.cnblogs.com/liming19680104/p/10397052.html等很多网上的方法,测试一下,发现我写 ...
- 五分钟学Java:如何学习Java面试必考的网络编程
原创声明 本文作者:黄小斜 转载请务必在文章开头注明出处和作者. 本文思维导图 简介 Java作为一门后端语言,对于网络编程的支持是必不可少的,但是,作为一个经常CRUD的Java工程师,很多时候都不 ...
- SSM整合搭建(二)
本页来衔接上一页继续来搭建SSM,再提一下大家如果不详细可以再去看视频哦,B站就有 之后我们来配置SpringMVC的配置文件,主要是配置跳转的逻辑 先扫描所有的业务逻辑组件 我们要用SpringMV ...
- 不要再认为Stream可读性不高了!
距离Java 8发布已经过去了7.8年的时间,Java 14也刚刚发布.Java 8中关于函数式编程和新增的Stream流API至今饱受"争议". 如果你不曾使用Stream流,那 ...
- 《Python学习手册 第五版》 -第17章 作用域
上一章的是函数的基础,因为函数在运用过程中,是可以嵌套的,函数中是会涉及到变量的,为了明确各自变量的使用范围,系统是有一套规则或者原则的,这就是作用域的概念 本章重点内容 1.作用域:作用域的概念 2 ...
- Callable的Future模式
一.线程实现方式 1.继承Thread类 2.实现Runnable接口 3.线程池 4.Callable 二.无论使用继承Thread类还是实现Runnable接口,还是使用线程池都没有办法解决2个问 ...