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. 学会了这些redis知识点,面试官会觉得你很nb(转自十年技术大牛)

    是数据结构而非类型 很多文章都会说,redis支持5种常用的数据类型,这其实是存在很大的歧义.redis里存的都是二进制数据,其实就是字节数组(byte[]),这些字节数据是没有数据类型的,只有把它们 ...

  2. Vue2.0 【第二季】第1节 Vue.directive自定义指令

    目录 Vue2.0 [第二季]第1节 Vue.directive自定义指令 一.什么是全局API? 二. Vue.directive自定义指令 三.自定义指令中传递的三个参数 四.自定义指令的生命周期 ...

  3. CSS核心概念之盒子模型

    盒子模型(Box Model) 关于更多CSS核心概念的文章请关注GitHub--CSS核心概念. 当对一个文档进行布局的时候,浏览器的渲染引擎会根据标准之一的 CSS 基础框盒模型(CSS basi ...

  4. cat、head、sed 三盟友

    在linux 中我们必不可少的会使用到这三个命令 他们有什么作用呢? 就是查看文档了,但他的功能远不止于此 来我们学习一下吧 cat [root@ESProbe ~]# cat --help Usag ...

  5. Selenium系列(一) - 8种元素定位方式的详细解读

    安装Selenium和下载Driver 安装selenium pip3 install  selenium -i http://pypi.douban.com/simple --trusted-hos ...

  6. Java基础语法(2)-变量

    title: Java基础语法(2)-变量 blog: CSDN data: Java学习路线及视频 1.什么是变量? 变量的概念 内存中的一个存储区域 该区域的数据可以在同一类型范围内不断变化 变量 ...

  7. hdu1224SPFA求最长路加上打印路径

    题目链接:http://icpc.njust.edu.cn/Problem/Hdu/1224/ 无负环. 代码如下: #include<bits/stdc++.h> using names ...

  8. Java BIO、NIO与AIO的介绍(学习过程)

    Java BIO.NIO与AIO的介绍 因为netty是一个NIO的框架,所以在学习netty的过程中,开始之前.针对于BIO,NIO,AIO进行一个完整的学习. 学习资源分享: Netty学习:ht ...

  9. java获取不同时段

    当前时间: long currentime= System.currentTimeMillis(); 本周第一天0时: Long weekstart = current.withDayOfWeek(1 ...

  10. Android之练习MVVM+DataBinding框架模式

    最近简单学习了MVVM框架,记录一下. 结果演示: 分析其功能在不同框架下的构成: 无框架 可以明显感受到在无框架下,虽然一个单独的Activity即可实现功能,但其负担过重,代码复查时繁琐,一旦需要 ...