1026. Table Tennis (30)-PAT

PAT真题练习(甲级)1026 Table Tennis (30 分)(含详细注释) PAT真题练习(甲级)1026 Table Tennis (30 分) 原题网址:https://pintia.cn/problem-sets/994805342720868352/problems/994805472333250560 A table tennis club has N tables available to the public. The tables are number... 阅读详情

1026. Table Tennis (30)

时间限制
400 ms
内存限制
32000 kB
代码长度限制
16000 B
判题程序
Standard
作者
CHEN, Yue

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
推荐指数:※※
题目本身并不难,需要考虑的业务因素比较多。PAT上很多题目都属于这种类型,题目本身不难,就是有很多业务因素要考虑(有时候是还没说清楚...)。
1.21:00:00时刻就不提供服务了
2.每组最多玩120分钟,超过时间直接赶人。
3.VIP首先会选择VIP球台,让后才是其他球台。
#include<iostream>
#include<string.h>
#include<string>
#include<vector>
#include<sstream>
#include<queue>
#include<string.h>
#include<math.h>
#include<stdio.h>
using namespace std;
int intime(){
	string in_time;
	int timeofint,tmp;
	cin>>in_time;
	stringstream streamint;

	streamint.clear();
	streamint<<in_time.substr(0,2);
	streamint>>tmp;
	timeofint=tmp*3600;

	streamint.clear();
	streamint.str(in_time.substr(3,5));
	streamint>>tmp;
	timeofint+=tmp*60;

	streamint.clear();
	streamint.str(in_time.substr(6,8));
	streamint>>tmp;
	timeofint+=tmp;

	return timeofint;
}
typedef struct play{
	int arr_time;
	int play_time;
	int tag;
	bool is_served;
}play;
void inttotime(int time_num){
	int hh,mm,ss;
	hh=time_num/3600;
	mm=(time_num%3600)/60;
	ss=((time_num%3600)%60)%60;
	printf("%02d:%02d:%02d",hh,mm,ss);
}
const int ear_time=8*3600;
vector< play > players;
int *tables, *servers,*vip_t;

void print_play(int f_play,int play_table,int tick){
	players[f_play].is_served=true;
	tables[play_table]=tick+players[f_play].play_time*60;
	servers[play_table]++;
	inttotime(players[f_play].arr_time);
	cout<<" ";
	inttotime(tick);
	printf(" %d\n",(tick-players[f_play].arr_time+30)/60);
}
int find_first_play(int tick,int is_vip_play){//find a person 
	int f_time=21*3600,f_play=-1;
	for(int t=0;t<players.size();t++){
		if(players[t].tag==1||is_vip_play==0)
			if(players[t].arr_time<f_time&&players[t].arr_time>=ear_time&&players[t].arr_time<=tick&&players[t].is_served==false){
				f_time=players[t].arr_time;
				f_play=t;
			}
	}
	return f_play;
}
int main()
{
	int n,k,m;
	int i,j,t;
	cin>>n;//total number of plays
	for(i=0;i<n;i++){
		play p;
		p.arr_time=intime();
		cin>>p.play_time;
		p.play_time=p.play_time>2*60?2*60:p.play_time;
		cin>>p.tag;
		p.is_served=false;
		players.push_back(p);
	}
	cin>>k;//number of tables
	tables=new int[k+1];
	servers=new int[k+1];
	vip_t=new int[k+1];
	for(i=1;i<=k;i++)
		tables[i]=8*3600;
	memset(servers,0,sizeof(int)*(k+1));
	memset(vip_t,0,sizeof(int)*(k+1));
	cin>>m;//the number of VIP tables;
	for(i=0;i<m;i++){
		int num;
		cin>>num;
		vip_t[num]=1;
	}
	int tick=0;
	for(tick=8*3600;tick<21*3600;tick++){
		for(j=1;j<=k;j++){
			if(tables[j]<=tick&&vip_t[j]==1){//fist check vip table
				int f_play;
				f_play=find_first_play(tick,1);
				if(f_play!=-1)//
					print_play(f_play,j,tick);

			}
		}
		for(j=1;j<=k;j++){//check every table [1,k]
			if(tables[j]<=tick){//this table is empty
				int f_play;
				f_play=find_first_play(tick,0);
				if(f_play!=-1)
					print_play(f_play,j,tick);
			}
		}
	}
	for(i=1;i<=k;i++){
		cout<<servers[i];
		if(i<k)
			cout<<" ";
	}
	return 0;
}


本地部署llama3Chinese 这通常意味着你的构建环境可能不完整或者没有正确配置。通常是由 Visual Studio 的 C++ 工具提供的。(大模型对错误的解析)错误信息表明在尝试构建一个项目时,在 Windows 上, 阅读详情

相关推荐

工厂自动化布线实战:从功率计算到线槽布局的完整避坑指南

本文详细介绍了工厂自动化布线的实战经验,从功率计算到线槽布局的完整避坑指南。通过三步计算法确定线径需求,强调电压降控制的重要性,并分享线槽布局的50%法则和强弱电分离技巧。特别针对移动设备和多芯信号线提供专业解决方案,帮助工程师避免常见错误,提升布线效率和质量。

weixin_29266007的博客 353

【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 any pair of players, if there are some tables open when they arrive, they will be assigned to t...

tjj1998的博客 556

Gitee自动创建PR之——评审模式

一 创建PR的常规操作 本地更新主干(一般为master分支),基于主干新建一个分支并(如Dev分支)切换; 进行新的需求开发; 将这个分支推送到远端; 打开 Gitee ,进入创建 Pull Request 界面; 选定目标分支(及我们需要合并到主干分支的分支,一般即为我们的开发分支); 填写 Title 以及 Description; 点击提交 Pull Request。 二 更快的常见PR的方式— — 评审模式 现在 Gitee.

calm_encode的博客 2994

【PAT(甲级)】1026 Table Tennis(易错点分析)

【PAT(甲级)】1026 Table Tennis(易错点分析) 有详细注释的代码

weixin_55202895的博客 614

使用Python下载ECMWF的ERA-5数据

一、注册账号 [官网]https://www.ecmwf.int/ 二、登录后获取下载key https://cds.climate.copernicus.eu/api-how-to 如图右侧红色框中的内容复制保存为TXT文件,并重命名为“.cdsapirc”,注意前面有点,保存在 C:\Users\username\.cdsapirc,(WINDOWS系统),username指当前电脑登录账户。 三、安装cdsapi库 以pycharm为例: 在pycharm中依次打开:File>setting

wise_sun的博客 7705

QtWebApp的使用【在Qt中搭建HTTP服务器】(一)

用Qt和QtWebApp能够实现在C++中开发HTTP Web服务器应用程序。 首先,需要先安装Qt的软件开发工具包。点此下载 其次,下载最新的QtWebApp库。点此下载 下载并解压缩QtWebApp ZIP文件。你将会看到: 如何使用QtWebApp 1)将QtWebApp.zip文件解压到文件夹中,并创建一个名为“ MyFirstWebApp”的新Qt控制台项目。然后,建立如下文件结构: 2)将以下行添加到MyFirstWebApp项目的项目文件中: QT += network include(

饭的笔记本 2万+

[PAT][ C++] 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...

沧海漂游的博客 597

用Unity Wheel Collider做坦克转向?3步实现履带式载具物理效果

本文详细解析了如何利用Unity的Wheel Collider组件实现履带式载具的差速转向物理效果。通过思维转换、场景搭建和核心代码实现三步,将Wheel Collider从模拟轮式车辆转向改造为控制履带扭矩差的系统,并深入探讨了参数调试与真实感提升的方法,帮助开发者打造物理反馈扎实的坦克或特种车辆模拟。

weixin_29009971的博客 223

PAT 1026. Table Tennis (30) 【26/30】

1026. Table Tennis (30) 时间限制 400 ms 内存限制 32000 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue A table tennis club has N tables available to

神州之光的专栏 1022

SpringBoot实现电子发票生成

电子发票是近年来比较流行的一种票据形式,它取代了以往传统的纸质发票,具有减少纸张浪费、方便有效查验等优点。本文将介绍如何使用Spring Boot和Vue.js构建一个仿真电子发票生成应用程序,借助微信二维码扫描功能和第三方库,实现用户扫描二维码获取发票信息并填写相关开票信息,最后生成电子发票。在本文中,我们介绍了如何使用Spring Boot和Vue.js构建一个仿真电子发票生成应用程序,借助微信二维码扫描功能和第三方库,实现用户扫描二维码获取发票信息并填写相关开票信息,最后生成电子发票。

不愧是暮言的博客 6093

开源机器人库orocos KDL 学习笔记(二):Geometric

开源机器人库orocos KDL 学习笔记二:Geometric 如果按照上一篇搭建的VS2015 orocos KDL环境,会出现3个例程:geometry, chainiksolverpos_lma_demo, trajectory_example. 这一篇看一下geometry的例程。 在frames.hpp中,定义了这些class: - class Vector - class R

行者无疆的博客 6703

PAT (Advanced Level) Practice - 1026 Table Tennis

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

EasonDongH的博客 344

Parasoft C++Test软件单元测试_操作指南

本文主要为使用C++TEST进行单元测试的流程性操作讲解,后续文章将以专题形式进行详细讲解,以及用一些被测函数作为示例进行实例讲解。

文章主要涉及嵌入式软件开发、测试、项目管理等,欢迎交流,共同进步。 1574

PAT 甲级1026 Table Tennis (30 分)

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 any pair of players, if there are some tables open when they arri...

努力不脱发的程序媛 505

C# WinForm 基于DirectShow.dll编写的程序,可边预览边保存视频,音频和图片

基于微软的DirectShow.dll的二次开发1.自动识别连接的摄像头跟麦克风且可以对其进行选择(默认选中第一个)2.可录制wmv和avi两种格式的视频并且都带有音频,avi可以录制的分辨率和帧数进行选择,wmv默认进行了淸晰度优化如不喜欢可去除代码中有相关提示3.可在预览点开之后进行拍照,也可边录制视频边拍照4.添加了视频和音频的压缩功能(酌情使用)这次二次开发发现C#对DirectShow的相关信息太少,这次做完也不敢藏私共享出来,还望大家指正

Statistics and Machine Learning Toolbox

Statistics and Machine Learning Toolbox(带书签),MATLAB统计学习工具

PAT A1026 Table Tennis (30分)

文章目录题目描述知识点我的实现码前思考代码实现码后反思 题目描述 1026 Table Tennis (30分) 又臭又长 知识点 大模拟! 我的实现 码前思考 直接跳过这道题,柳神说了:pat现在不考这种题了! 代码实现 #include <iostream> #include <vector> #include <algorithm> #include <cmath> using namespace std; struct person { i.

yc_cy1999的博客 587

文档:亲测可用解决vnc灰屏,黑屏,鼠标大黑叉情况

主要解决vnc-viewer灰屏,黑屏,鼠标大黑叉等现象,详细见文档。

PAT-1026 Table Tennis (30)

牛客网上过了,pat练题 18 分。所以关于题目大意和解题思路可能有些不对。。。吐槽下:这题坑好多,有多个方面的细节题目都没说清。真心花了很多时间,但还是不知道自己哪错了。。。题目链接:https://www.patest.cn/contests/pat-a-practise/1026#include &lt;iostream&gt; #include &lt;algo...

zhoujian_1943的博客 401

jre9下载 jdk9

(Java SE Runtime Environment 9.0) 9.0u175 官方最新版 【x86|x64】

PAT甲级 1026 Table Tennis (30分)

题目链接: https://pintia.cn/problem-sets/994805342720868352/problems/994805472333250560 思路: 据说现在PAT已经不考这种大模拟了,准备PAT的同学可以酌情跳过节省时间~ 我的想法是用优先队列保存即将要发生的事件(一共三种事件),先发生的排在前面。用户排队的情况我是使用两个队列分别存储vip和普通用户的。接下来我们一个一个处理这些事件即可: (1)有vip过来打球。若有空桌,则先选择vip桌中序号最小桌,若无空vip桌则选

Yuhan的博客 446

pat A1026 Table Tennis (30 分)

个人认为是pat甲级里最难的一道了 //pat A1026 Table Tennis (30 分) //两个注意点: //1、如果存在空闲的vip球桌,则vip客户总是有限选择编号最小的空闲的vip球桌,而不是选择编号最小的空闲的球桌 //2、如果有多张空闲的球桌,则选择编号最小的球桌,而不是选择最早空出的球桌。 #include &lt;cstdio&gt; #include &lt;...

qq_38705851的博客 524

PAT 1026. Table Tennis (30)

题意: 1.当前无vip用户时,普通用户按照空余桌子的号码依次就坐。 2.当前有vip用户,没有空余的vip桌子时,vip当做普通用户进入队列排序;                 有空余的vip桌子时,应该先就做vip座位; 基本算法: 类似于mergeSort的方法,将vip用户和扑通用户区分,然后分别sort,接下来计算merge看每个用户进入队列的时间。 排队题的基本思想

xuxumoi 2487

1026. Table Tennis (30)-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 any pair of players, if there are some tables open when they arrive, they wi

柳婼 の blog 3958

PAT A 1026 Table Tennis (30分)

1026 Table Tennis (30分) 感谢:siukwan大佬的帖子https://blog.csdn.net/jmlikun/article/details/49821845。测试例子是真的很宝贵。 吐槽 这题简直就是毒瘤。考试遇到这种题是真的当场暴毙。过于复杂已经吐不出槽了。 题目易漏细节要求 当VIP用户正常排到队时,如果同时有VIP座位和非VIP座位空着,他会优先选择VIP座位...

虚境的博客 322

PAT Advanced 1026 Table Tennis (30)

问题描述: 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,...

kircher的博客 190

PAT_A 1026. Table Tennis (30模拟)

1026. Table Tennis (30模拟)

longtails的博客 1495

PAT 甲级 1026 Table Tennis(30 分)

比较坑,题目意思表达不清楚,又是纯属烧脑逻辑题 要注意的点就是:等待的vip用户在有最小编号vip球桌的情况下选择最小编号球桌,跳过其之前等待的普通用户。 看别的博客,有别的大佬 测试的过程中发现,对于一个非vip玩家,如果达到时有很多空闲的桌子,不显式的写明代码让他去选择桌子号最小的空闲桌子也可以通过所有的测例。 #include<iostream> #inc...

weixin_30273763的博客 207

PAT甲级1026 Table Tennis (30 分)

1026Table 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 w...

Dexter 276

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

qq_45478482的博客 276
上一篇: 1018. Public Bike Management (30)-PAT
下一篇: 1011. Sticks(木棒) -POJ
zoushidexing
博客等级 码龄18年 70粉丝 171原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值