题目https://pintia.cn/problem-sets/994805342720868352/problems/994805472333250560

题意:

有k张乒乓球桌,有的是vip桌。有n对玩家来打乒乓,有的玩家是VIP玩家。

当他们到达时,如果没有空桌子他们就排队等待。

这时候如果有VIP桌子空出来了,那么就优先给队列里的VIP玩家,如果没有VIP玩家就给普通玩家。

如果普通桌子空出来了,就给队列里排在最前的玩家。

如果玩家到达的时候有好多桌子可以选择,那么他会选择桌号最小的那张,VIP玩家会优先选择桌号最小的VIP桌子【这题意真的....】

每对玩家最多只能玩两个小时。

营业时间是上午八点到晚上九点。如果在晚上九点还没开始玩就不能玩了。

最后输出每对玩家到达时间,开始玩的时间和(四舍五入后的)等待时间。

思路:

我好菜系列。PAT真是练模拟的好地方。

首先根据输入把时间按照秒预处理。然后把所有玩的时间超过2小时的设置为2小时。

建两个玩家队列,把VIP玩家和非VIP玩家分开,分别遍历直到两个队列都为空。

对于队首的VIP玩家和非VIP玩家我们先根据他们到达的最早时间找到一张合法的桌子(不管是VIP桌还是非VIP桌)table1

然后我们再根据VIP玩家到达的时间找到桌号最小的VIP桌。table2

找的过程是:如果当前桌子的结束时间小于当前时间,那么break,如果找不到小于的就要在大于之中找到结束时间最早的一张桌子。

之后我们判断到底是VIP玩家先玩还是非VIP玩家先玩。

如果非VIP到的比VIP早,并且table1的结束时间比VIP到达的早,那么非VIP先玩。

如果非VIP到的比VIP早,并且table1不是VIP桌,那么非VIP也先玩。

否则就是VIP先玩。

如果是VIP先玩,那么他应该要选择合法的桌号最小的VIP桌,也就是table2

然后更新这对玩家的时间还有桌子的结束时间和数量。根据是谁玩的,决定是哪个队列的下标+1.

由于有的玩家玩不到了,所以每对玩家还需要用一个vis标记是否玩了。

四舍五入可以适用round()函数。

 #include<cstdio>
#include<cstdlib>
#include<map>
#include<set>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<vector>
#include<cmath>
#include<stack>
#include<queue> #define inf 0x7fffffff
using namespace std;
typedef long long LL;
typedef pair<string, string> pr; int n;
const int maxn = 1e4 + ;
int k, m;
int cnt[]; struct player{
int id;
int arrive_time;
int play_time;
bool vip;
int serve_time = ;
int wait;
bool can = false;
}peo[maxn]; struct table{
int id;
int finish_time = ;
bool vip = false;
bool operator < (table b)const{
if(finish_time == b.finish_time)return id > b.id;
return finish_time > b.finish_time;
}
}tab[]; bool cmp(player a, player b)
{
return a.arrive_time < b.arrive_time;
} bool cmp1(player a, player b)
{
return a.arrive_time + a.wait < b.arrive_time + b.wait;
} int findd(int t, int type)
{
int ret = , ans = ;
for(int i = ; i <= k; i++){
if(type && !tab[i].vip)continue;
if(tab[i].finish_time < t){
ans = i;
break;
}
else if(tab[i].finish_time < ret){
ans = i;
ret = tab[i].finish_time;
}
}
return ans;
} vector<player>que[];
int main()
{
scanf("%d", &n);
for(int i = ; i <= n; i++){
int h, m, s;
peo[i].id = i;
scanf("%d:%d:%d %d %d", &h, &m, &s, &peo[i].play_time, &peo[i].vip);
peo[i].arrive_time = (h - ) * * + m * + s;
if(peo[i].play_time > )peo[i].play_time = ;
peo[i].play_time *= ;
que[peo[i].vip].push_back(peo[i]);
}
peo[n + ].arrive_time = peo[n + ].arrive_time = 1e8;
que[].push_back(peo[n + ]);
que[].push_back(peo[n + ]);
scanf("%d %d", &k, &m);
for(int i = ; i < m; i++){
int t;
scanf("%d", &t);
tab[t].vip = true;
} sort(que[].begin(), que[].end(), cmp);
sort(que[].begin(), que[].end(), cmp);
int i = , j = , num = ;
while(){
int time1 = que[][i].arrive_time, time2 = que[][j].arrive_time;
int tableid = findd(min(time1, time2), );
int viptab = findd(time2, );
if(tab[tableid].finish_time >= * * || min(time1, time2) >= * * )break;
int who;
if(tab[tableid].vip == )who = (time1 < time2)?:;
else who = (max(tab[tableid].finish_time, time1) > time2)?:;
if(who && viptab && tab[viptab].finish_time <= time2)tableid = viptab;
int peoid = (who == )?que[][i].id:que[][j].id;
peo[peoid].serve_time = max(tab[tableid].finish_time, peo[peoid].arrive_time);
peo[peoid].wait = peo[peoid].serve_time - peo[peoid].arrive_time;
tab[tableid].finish_time = peo[peoid].serve_time + peo[peoid].play_time;
cnt[tableid]++;
peo[peoid].can = true;
if(who)j++;
else i++;
//num++;
} sort(peo + , peo + + n, cmp1);
for(int i = ; i <= n; i++){
if(peo[i].wait < )peo[i].wait = ;
if(!peo[i].can)continue;
int h, m, s;
h = peo[i].arrive_time / ( * ) + ;
m = peo[i].arrive_time % ( * );
m = m / ;
s = peo[i].arrive_time % ;
printf("%02d:%02d:%02d ", h, m, s);
h = (peo[i].arrive_time + peo[i].wait) / ( * ) + ;
m = (peo[i].arrive_time + peo[i].wait) % ( * );
m = m / ;
s = (peo[i].arrive_time + peo[i].wait) % ;
printf("%02d:%02d:%02d ", h, m, s);
//cout<<(peo[i].wait + 30) / 60<<endl;
cout<<round(1.0 * peo[i].wait / 60.0)<<endl;
//printf("%d\n", round(1.0 * peo[i].wait / 60.0)); }
printf("%d", cnt[]);
for(int i = ; i <= k; i++){
printf(" %d", cnt[i]);
}
printf("\n");
return ;
}

PAT甲级1026 Table Tennis【模拟好题】的更多相关文章

  1. PAT甲级1026. Table Tennis

    PAT甲级1026. Table Tennis 题意: 乒乓球俱乐部有N张桌子供公众使用.表的编号从1到N.对于任何一对玩家,如果有一些表在到达时打开,它们将被分配给具有最小数字的可用表.如果所有的表 ...

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

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

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

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

  4. PAT甲级——A1026 Table Tennis

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

  5. PAT 1026 Table Tennis[比较难]

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

  6. PAT 1026. Table Tennis

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

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

  8. 1026. Table Tennis (30)

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

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

随机推荐

  1. NOIP2010普及组 导弹拦截

    导弹拦截 OJ地址: https://www.luogu.org/problemnew/show/P1158 http://codevs.cn/problem/1128/   题目描述 Descrip ...

  2. 最完整苹果IOS个人开发账号升级方法-个人开发账号升级为公司开发者账号常见误区

    1:背景交代 大概晚上10点钟之后在知乎上看到很多人聊审核被拒PLA1.2,主要电商和金融类APP被拒很多.主要原因是 1:发布的APP与改账号关联度很低.(说白苹果怀疑你是山寨APP,不是优质的AP ...

  3. VMWare 虚机迁移后Linux系统网卡启动问题

    重新安装VMWare或拷贝虚机文件后有时网卡会无法工作,主要是因为网卡的Mac地址改变了,如果系统中的网卡配置信息中有Mac的信息,则虚机的系统的网卡可能无法正常工作. 如果出现上述问题,解决办法如下 ...

  4. ElasticSearch 5.0及head插件安装

    一.elasticsearch安装配置 1.官网下载源码包 https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-5.0 ...

  5. 自建证书配置HTTPS服务器

    1.写这篇博客的初衷是因为最近iOS9出来了,苹果官方默认要求使用HTTPS,所以自己想整一个HTTPS服务器,也想好好了解一下HTTPS通信,也知道了HTTPS其实就是在HTTP的基础上加上了SSL ...

  6. Tomcat connectionTimeout问题定位处理

    问题现象 在某个时刻,后端收到了平时4-6倍的请求(保密起见,略去产品和事件),在10分钟后居然没有请求可以接进来 问题原因 经过分析,首先,是后端服务器的线程池满了,线程池满的原因:1.server ...

  7. Introducing DataFrames in Apache Spark for Large Scale Data Science(中英双语)

    文章标题 Introducing DataFrames in Apache Spark for Large Scale Data Science 一个用于大规模数据科学的API——DataFrame ...

  8. R8500 MPv2 版本 刷梅林改版固件

    由于R8500折腾起来比较繁琐.并且国内的koolshare上已经有人释出梅林改版移植的固件,主要是***更方便了,所以把R8500刷成了梅林固件,这是我第一次用上梅林固件. 刷机整个过程参考了下面的 ...

  9. Atitit 关于处理环保行动联盟和动物解放阵线游击队的任命书 委任状

    Atitit 关于处理环保行动联盟和动物解放阵线游击队的任命书 委任状 Uke 集团文化部部长兼emir 大酋长圣旨到!! In god we trust ,Emir Decree大酋长圣旨:: En ...

  10. golang:常量

    今天写代码的时候才发现,go语言里面的常量不能是数组(例如:[2]byte) 于是想查一下资料搞清楚到底是什么原因导致的,从effective go查到如下介绍: 但是这里也仅仅就是介绍了一下常量类型 ...