队列模拟题——pat1026. Table Tennis
题意自己理解了,主要是两个队列维护,一个VIP队列,一个普通队列
搜集了一些坑(有些坑转自别的网站用于广大同学的测试之用)
普通人也有VIP的权益!!! 屌丝逆袭有木有!!!
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
10 10
1 2 3 4 5 6 7 8 9 10
08:00:00 08:00:00 0
08:01:30 08:01:30 0
08:02:00 08:02:00 0
08:10:00 08:10:00 0
08:12:00 08:12:00 0
20:50:00 20:50:00 0
20:51:00 20:51:00 0
20:52:00 20:52:00 0
20:53:00 20:53:00 0
2 2 2 2 1 0 0 0 0 0
1.当有多个乒乓球台空闲时,vip顾客到了会使用最小id的vip球台,而不是最小id的球台,测试以下用例:
2
10:00:00 30 1
12:00:00 30 1
5 1
3
输出正确结果应为:
10:00:00 10:00:00 0
12:00:00 12:00:00 0
0 0 2 0 0
2.题目要求每对顾客玩的时间不超过2小时,那么当顾客要求玩的时间>2小时的时候,应该截断控制,测试以下用例:
2
18:00:00 180 1
20:00:00 60 1
1 1
1
输出的正确结果应为:
18:00:00 18:00:00 0
20:00:00 20:00:00 0
2
3.虽然题目中保证客户到达时间在08:00:00到21:00:00之间,但是根据最后的8个case来看,里面还是有不在这个时间区间内到达的顾客,所以建议还是稍加控制,测试以下用例:
1
21:00:00 80 1
1 1
1
输出的正确结果应为:
0
4.题目中说的round up to an integer minutes是严格的四舍五入,需要如下做:
wtime = (stime - atime + 30) / 60
而不是:
wtime = (stime - atime + 59) / 60
代码这次写的还是可以一看的,就贴上来吧
#include<stdio.h>
#include<queue>
#include<algorithm>
#include<iostream>
using namespace std; struct VIPdata{//vip队列
int starts;
int startget;
int lasts;
int VIP;
int id; friend bool operator <(VIPdata x,VIPdata y){
if(x.VIP==y.VIP)
return x.starts>y.starts;
else
return x.VIP<y.VIP;
}
}s[]; struct Ordata{//普通队列
int starts;
int startget;
int lasts;
int VIP;
int id;
Ordata(int a,int b,int c,int d,int e){
starts=a;startget=b;lasts=c;VIP=d;id=e;
}
friend bool operator <(Ordata x,Ordata y){
return x.starts>y.starts;
}
}; int ifplay[];//某人是否已经玩过 int cmp(VIPdata x,VIPdata y){
return x.starts<y.starts;
} struct Table{
int ifuse;
int end;
int vip;
int useNum;
}table[]; int main(){
int n,tableNum,VipNum,PuNum;
while(scanf("%d",&n)!=EOF){
int i,hh,mm,ss,j;
for(i=;i<=n;i++){
ifplay[i]=;
scanf("%d:%d:%d",&hh,&mm,&ss);
s[i].starts=hh*+mm*+ss;
scanf("%d",&mm);
if(mm>)mm=;//不要超过2个小时
s[i].lasts=mm*;
scanf("%d",&s[i].VIP);
s[i].id=i;
}
scanf("%d",&tableNum);
scanf("%d",&VipNum);
PuNum=tableNum-VipNum; for(i=;i<=tableNum;i++){
table[i].ifuse=;
table[i].end=;
table[i].vip=;
table[i].useNum=;
}
int temp;
for(i=;i<=VipNum;i++){
scanf("%d",&temp);
table[temp].vip=;
} sort(&s[],&s[+n],cmp);
//for(i=1;i<=n;i++){
// printf("%02d:%02d:%02d %d\n",s[i].starts/3600,(s[i].starts%3600)/60,s[i].starts%60,s[i].VIP);
//}
int first=*,end=*;
int Vipnow=,Punow=;
priority_queue<Ordata>Orqq;
priority_queue<VIPdata>VIPqq; j=;
int k,x;
for(i=first;i<end;i++){
for(k=;k<=tableNum;k++){//退台球桌
if(table[k].ifuse==)continue;
if(table[k].end==i){
table[k].ifuse=;
if(table[k].vip==)Vipnow--;
else Punow--;
table[k].ifuse=;
}
} //到点的人排队
while(s[j].starts==i&&j<=n){
Orqq.push(Ordata(s[j].starts,s[j].startget,s[j].lasts,s[j].VIP,s[j].id));
VIPqq.push(s[j]);j++;
} if((Vipnow+Punow)==tableNum)continue;
for(k=Vipnow+;k<=VipNum;k++){//排队中的人进台球桌 有VIP桌先满足VIP
if(VIPqq.empty())break;
if(VIPqq.top().VIP==)break; while(!VIPqq.empty()&&ifplay[VIPqq.top().id]==/*||(VIPqq.top().lasts+i)>end)*/){
VIPqq.pop();
}if(VIPqq.empty())break; int rx=-;
for(x=;x<=tableNum;x++){
if(table[x].ifuse==)continue;
if(table[x].vip==)continue;
rx=x;break;
}if(rx==-)break; printf("%02d:%02d:%02d",(VIPqq.top().starts/),(VIPqq.top().starts%)/,VIPqq.top().starts%);
printf(" %02d:%02d:%02d",(i/),(i%)/,i%);
printf(" %d\n",(i-VIPqq.top().starts+)/);//这里注意+30 table[rx].end=VIPqq.top().lasts+i;
table[rx].ifuse=;
table[rx].useNum++;
Vipnow++;
ifplay[VIPqq.top().id]=;
VIPqq.pop(); } //排队中的人进台球桌 现在按普通队列排
if((Vipnow+Punow)==tableNum)continue;
for(k=;k<=tableNum;k++){//普通人也可以玩VIP桌子
if(Orqq.empty())break; while(!Orqq.empty()&&ifplay[Orqq.top().id]==){
Orqq.pop();
}if(Orqq.empty())break; int rx=-;
for(x=;x<=tableNum;x++){
if(table[x].ifuse==)continue;
rx=x;break;
}if(rx==-)break; printf("%02d:%02d:%02d",(Orqq.top().starts/),(Orqq.top().starts%)/,Orqq.top().starts%);
printf(" %02d:%02d:%02d",(i/),(i%)/,i%);
printf(" %d\n",(i-Orqq.top().starts+)/);//这里注意+30 table[rx].end=Orqq.top().lasts+i;
table[rx].ifuse=;
table[rx].useNum++;
if(table[rx].vip==)Vipnow++;
else
Punow++;
ifplay[Orqq.top().id]=;
Orqq.pop();
}
}
int ok=;
for(i=;i<=tableNum;i++){
if(ok==)ok=;
else printf(" ");
printf("%d",table[i].useNum);
}printf("\n");
}
return ;
}
队列模拟题——pat1026. Table Tennis的更多相关文章
- uva 12100 Printer Queue 优先级队列模拟题 数组模拟队列
题目很简单,给一个队列以及文件的位置,然后一个一个检查,如果第一个是优先级最高的就打印,否则放到队列后面,求所要打印的文件打印需要花费多长时间. 这里我用数组模拟队列实现,考虑到最糟糕的情况,必须把数 ...
- PAT 甲级 1026 Table Tennis(模拟)
1026. Table Tennis (30) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue A table ...
- PAT A1026 Table Tennis (30 分)——队列
A table tennis club has N tables available to the public. The tables are numbered from 1 to N. For a ...
- Codeforces Round #397 by Kaspersky Lab and Barcelona Bootcamp (Div. 1 + Div. 2 combined) C. Table Tennis Game 2 水题
C. Table Tennis Game 2 题目连接: http://codeforces.com/contest/765/problem/C Description Misha and Vanya ...
- Codeforces Round #304 (Div. 2) C. Soldier and Cards —— 模拟题,队列
题目链接:http://codeforces.com/problemset/problem/546/C 题解: 用两个队列模拟过程就可以了. 特殊的地方是:1.如果等大,那么两张牌都丢弃 : 2.如果 ...
- Pat(Advanced Level)Practice--1026(Table Tennis)
Pat1026代码 题目描写叙述: A table tennis club has N tables available to the public. The tables are numbered ...
- PAT甲级1026. Table Tennis
PAT甲级1026. Table Tennis 题意: 乒乓球俱乐部有N张桌子供公众使用.表的编号从1到N.对于任何一对玩家,如果有一些表在到达时打开,它们将被分配给具有最小数字的可用表.如果所有的表 ...
- 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[比较难]
1026 Table Tennis (30)(30 分) A table tennis club has N tables available to the public. The tables ar ...
随机推荐
- crontab执行定时任务
在linux下面使用命令crontab -e 编辑任务: [adv@localhost]$ crontab -e 之后开始编辑任务 * * * * * cd /home/adv/work/cutte ...
- Java复习11. 单例编程
Java复习11. 单例编程 1.最简单的写法,那个方式是线程不安全的 public class Singleton { private static Singleton instance; ...
- gitblit-部署
什么是 Gitblit Gitblit是一个开源的用于管理,查看和提供Git仓库. 它主要设计为希望托管集中存储库的小工作组的工具. Gitblit有什么特点 Gitblit部署示例1 日常维护添加步 ...
- log4cpp单例类封装
body, table{font-family: 微软雅黑; font-size: 13.5pt} table{border-collapse: collapse; border: solid gra ...
- 一台服务器的IIS绑定多个域名
等待十分钟: 在IIS上配置:
- 将VIM打造成强大的IDE
转载自:所需即所获:像 IDE 一样使用 vim 如侵犯您的版权,请联系:2378264731@qq.com --------------------------------------------- ...
- awk结合正则匹配
利用awk分析data.csv中label列各取值的分布. 在终端执行head data.csv查看数据: name,business,label,label_name 沧州光松房屋拆迁有限公司,旧房 ...
- 使用HslCommunication实现PLC数据的远程客户端监视,以及web端实时监视,远程操作设备示例
前言 本文主要是演示一个例子,服务器后台程序从PLC采集数据,并推送给在线客户端显示,以及推送给web端进行实时的显示,还支持远程操作,支持安卓端的同步监视和远程操作,关于HslCommunicati ...
- linux系统编程-进程
进程 现实生活中 在很多的场景中的事情都是同时进行的,比如开车的时候 手和脚共同来驾驶汽车,再比如唱歌跳舞也是同时进行的: 如下是一段视频,迈克杰克逊的一段视频: http://v.youku.com ...
- java之继承
措辞 类Y是继承类X == 类X是类Y的父类 == Y IS-A X IS-A测试具有传递性,即:若Y IS-A X,且Z IS-A Y,则Z IS-A X IS-A关系是单向的 条件 为了防止继承被 ...