PAT1026 (大模拟)
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台子可以空出来。
最初想分情况讨论,写的很复杂,时间还会超时。对于这种问题,可以这样来解决的:
依次找最先空出来的台子,在刚进来的人中,根据是否是vip,空出的台子是否为vip进行分配。
代码如下:
#include<iostream>
#include<cstdio>
#include<vector>
#include<algorithm>
#include<cmath>
using namespace std;
struct pla{
int arrive,start,p,tag;
};
struct tab
{
int end=*;
int vip,num;
};
vector<pla>player;
vector<tab>table;
const int inf=0x3f3f3f3f;
bool cmp1(pla a,pla b)
{
return a.arrive<b.arrive;
}
bool cmp2(pla a,pla b)
{
return a.start<b.start;
}
int findvip(int id)
{
id++;
while(id<player.size()&&player[id].tag!=)
id++;
return id;
}
void allocate(int person,int index)
{ if(player[person].arrive<=table[index].end)
player[person].start=table[index].end;
else
player[person].start=player[person].arrive;
//cout<<person<<" "<<index<<player[person].start<<" "<<player[person].arrive<<endl;
table[index].end=player[person].start+player[person].p;
table[index].num++;
}
int main()
{
int n;
scanf("%d",&n);
for(int i=;i<=n;i++)
{
int h,m,s,p,tag;
scanf("%d:%d:%d %d %d",&h,&m,&s,&p,&tag);
pla temp;
temp.arrive=h*+m*+s;
temp.start=*;
if(temp.arrive>=*) //是否不符合条件
continue;
temp.p=p<=?p*:; //测试用例有超过2小时的情况
temp.tag=tag;
player.push_back(temp);
}
int k,m;
scanf("%d%d",&k,&m);
table.resize(k+);
for(int i=;i<=m;i++)
{
int tmp;
scanf("%d",&tmp);
table[tmp].vip=;
}
sort(player.begin(),player.end(),cmp1);
int i=,vipid=-;
vipid=findvip(vipid); //寻找vip成员
while(i<player.size())
{
int index=-,minendtime=inf;
for(int j=;j<=k;j++) //寻找最早结束的桌子
{
if(table[j].end<minendtime)
{
minendtime=table[j].end;
index=j;
}
}
if(table[index].end>=*)
break;
if(player[i].tag==true&&i<vipid) //说明此vip已经分配过了
{
i++;
continue;
}
if(table[index].vip==)
{
if(player[i].tag==)
{
allocate(i,index);
if(vipid==i)
vipid=findvip(vipid);
i++;
}
else
{
if(vipid<player.size()&&player[vipid].arrive<=table[index].end)
{
allocate(vipid,index);
vipid=findvip(vipid);
}
else
{
allocate(i,index);
i++;
}
}
}
else
{
if(player[i].tag!=)
{
allocate(i,index);
i++;
}
else
{
int vipindex=-,vipendtime=inf;
for(int j=;j<=k;j++)
{
if(table[j].vip==&&table[j].end<vipendtime)
{
vipindex=j;
vipendtime=table[j].end;
}
}
if(vipindex!=-&&player[i].arrive>=table[vipindex].end)
{
allocate(i,vipindex);
if(i==vipid)
vipid=findvip(vipid);
i++;
}
else
{
allocate(i,index);
if(i==vipid)
vipid=findvip(vipid);
i++;
} }
}
}
sort(player.begin(),player.end(),cmp2);
for(int i=;i<player.size()&&player[i].start<*;i++)
{
printf("%02d:%02d:%02d ",player[i].arrive/,player[i].arrive%/,player[i].arrive%);
printf("%02d:%02d:%02d ",player[i].start/,player[i].start%/,player[i].start%);
printf("%.0f\n",round((player[i].start-player[i].arrive)/60.0));
}
for(int i=;i<table.size();i++)
{
if(i!=)
printf(" ");
printf("%d",table[i].num);
}
}
PAT1026 (大模拟)的更多相关文章
- HDU 5920 Ugly Problem 高精度减法大模拟 ---2016CCPC长春区域现场赛
题目链接 题意:给定一个很大的数,把他们分为数个回文数的和,分的个数不超过50个,输出个数并输出每个数,special judge. 题解:现场赛的时候很快想出来了思路,把这个数从中间分为两部分,当位 ...
- AC日记——神奇的幻方 洛谷 P2615(大模拟)
题目描述 幻方是一种很神奇的N*N矩阵:它由数字1,2,3,……,N*N构成,且每行.每列及两条对角线上的数字之和都相同. 当N为奇数时,我们可以通过以下方法构建一个幻方: 首先将1写在第一行的中间. ...
- ACdream 1188 Read Phone Number (字符串大模拟)
Read Phone Number Time Limit:1000MS Memory Limit:64000KB 64bit IO Format:%lld & %llu Sub ...
- 2016ACM-ICPC网络赛北京赛区 1001 (trie树牌大模拟)
[题目传送门] 1383 : The Book List 时间限制:1000ms 单点时限:1000ms 内存限制:256MB 描述 The history of Peking University ...
- Bzoj1972: [Sdoi2010]猪国杀 题解(大模拟+耐心+细心)
猪国杀 - 可读版本 https://mubu.com/doc/2707815814591da4 题目可真长,读题都要一个小时. 这道题很多人都说不可做,耗时间,代码量大,于是,本着不做死就不会死的精 ...
- (大模拟紫题) Luogu P1953 易语言
原题链接:P1953 易语言 (我最近怎么总在做大模拟大搜索题) 分别处理两种情况. 如果只有一个1或0 直接设一个cnt为这个值,每次输入一个新名字之后把数字替换成cnt,最后cnt++即可. 注意 ...
- NOIP2017 时间复杂度 大模拟
再写一道大模拟题. 由于是限时写的,相当于考场代码,乱的一批. 题目链接:P3952 时间复杂度 先记几个教训: 字符串形式的数字比较大小老老实实写函数,字典序都搞错几次了 栈空的时候不但pop()会 ...
- [CSP-S模拟测试]:引子(大模拟)
题目描述 网上冲浪时,$Slavko$被冲到了水箱里,水箱由上而下竖直平面.示意图如下: 数字$i$所在的矩形代表一个编号为$i$的水箱.1号水箱为水箱中枢,有水管连出.除了$1$号水箱外,其他水箱上 ...
- 模拟赛38 B. T形覆盖 大模拟
题目描述 如果玩过俄罗斯方块,应该见过如下图形: 我们称它为一个 \(T\) 形四格拼板 .其中心被标记为\(×\). 小苗画了一个 \(m\) 行 \(n\) 列的长方形网格.行从 \(0\) 至 ...
随机推荐
- jsp取addFlashAttribute值深入理解即springMVC发redirect传隐藏参数
结论:两种方式 a.如果没有进行action转发,在页面中el需要${sessionScope['org.springframework.web.servlet.support.SessionFlas ...
- day02-格式化输出
python格式化字符串有%和{}两种 字符串格式控制符. 字符串输入数据格式类型(%格式操作符号) %%百分号标记%c字符及其ASCII码%s字符串%d有符号整数(十进制)%u无符号整数(十进制)% ...
- js模板引擎初级
模板引擎:模板引擎(这里特指用于Web开发的模板引擎)是为了使用户界面与业务数据(内容)分离而产生的,它可以生成特定格式的文档,用于网站的模板引擎就会生成一个标准的html文档. 模板引擎的实现方式有 ...
- win10 任务栏锁定,win键没反应
现象:之前用win10,换成win10专业版后,安装360优化系统,过了几天后突然发现任务栏好像被锁定一般,按windows键没有任何反应,任务栏打开的文件,图片等等右键也没有反应,讲道理应该有关闭选 ...
- React.createElement: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: undefined.
昨天在项目中,重新封装组件时,引用了原来的一个子组件,但发现子组件在其他页面正常,在新的组件里面就发生保存, 然后把子组件注释,随便显示其div元素也正常,纠结了很久,最后发现引用的方式有问题 子组件 ...
- SQL 语句 写法
SELECT * FROM article where userid=4 order by sort asc LIMIT 0,10; 先根据写where 条件,再排序,在LIMIT.
- Android DevArt5:如何在Android中创建多线程?
本篇内容: 如何在Android中创建多进程?查看进程的三种方式有哪些? 多进程模式的运行机制?- 演示了多进程出现问题中的两种情况: 静态成员失效 Application多次创建 IPC基础概念介绍 ...
- T-SQL行合并成列与列拆分成行
本文出处:http://www.cnblogs.com/wy123/p/6910468.html 感觉最近sql也没少写,突然有一点生疏了,对于用的不是太频繁的一些操作,时间一久就容易生. 多行的某一 ...
- 11.mysql-权限.md
目录 -- ***********五.mysql权限问题**************** -- mysql数据库权限问题:root :拥有所有权限(可以干任何事情) -- 权限账户,只拥有部分权限(C ...
- fengsuo
IP地址特定端口封锁 原理: 配合上文中特定IP地址封锁里路由扩散技术封锁的方法进一步精确到端口,从而使发往特定IP地址上特定端口的数据包全部被丢弃而达到封锁目的,使该IP地址上服务器的部分功能无法在 ...