【分步处理的妙处】 校练习赛Problem D——Dinner Hall (附judge地址)

本文介绍了一个使用学生收集的数据来分析校园内多个餐厅客户流量的方法。通过对进出记录的时间戳和事件类型的处理,确定任意时刻餐厅内可能的最大人数。该问题考虑到了数据缺失情况,并通过合理的假设来解决未知事件的问题。

链接:点击打开链接,密码xx316,Problem D

这个是我们队内练习比赛时出现过的一道题,比较有代表性的分步处理。思路比较好懂,同队的ZH同学WA了若干次,只是因为问号的位置不能笼统的认为是进或者是出,应该通过比较最大可进值(就是说在当前情况下最多能进入的人数,满足以后出去的人起码要等于进去的人。这样的话,对每一步的最大理论进人数进行比较即可得出最后的结果。

Description

Download as PDF

The University administration plans to build a new dinner hall, to replace the several small (and rather inadequate) dinner halls spread over the campus. To estimate the number of places needed in the new dinner hall, they performed an experiment to measure the maximum total number of clients inside the existing dinner halls at any time. They hired several students as pollers, and positioned one poller at each entrance and each exit of the existing dinner halls. The pollers' task was to note in small cards the time each client entered or exited the hall (one card for each event). In each card they wrote the time, in the format HH:MM:SS, and the associated event (letter `E' for an entry, letter `X' for and exit).

The experiment started in the morning, before breakfast, and ended in the evening, after dinner. The pollers had their watches synchronized, and the halls were empty both before and after the experiment (that is, no client was inside a hall before the experiment began, and no client remained in a hall after the experiment ended). The pollers wrote exactly one card for every client who entered a hall and for every client who exited a hall.

After the experiment, the cards were collected and sent to the administration for processing. The task, however, was not as easy as planned, because two problems were detected. Firstly, the cards were bunched together in no particular order and therefore needed sorting; that is fairly easy, but time-consuming to do by hand. But what is worse is that, although all cards had a valid time, some pollers forgot to write the letter specifying the event. The University administration decided they needed help from an expert!

Given a set of cards with times and the indication of the event (the indication of the event may be missing), write a program to determine the maximum number of clients that could possibly had been inside the dinner halls in a given instant of time.

Input

The input contains several test cases. The first line of a test case contains one integer N indicating the number of cards collected in the experiment (2$ \le$N$ \le$64800). Each of the next N lines contains the information written in a card, consisting of a time specification, followed by a single space, followed by an event specification. A time specification has the format HH : MM : SS, where HH represents hours (06$ \le$HH$ \le$23)MM represents minutes (00$ \le$MM$ \le$59) and SS represents seconds (00$ \le$SS$ \le$59). Within a test case, no two cards have the same time. An event specification is a single character: uppercase `E' for entry, uppercase `X' for exit and `?' for unknown. Information may be missing, but the information given is always correct. That is, the times noted in all cards are valid. Also, if a card describes an entry, then a client did enter a hall at the informed time; if a card describes an exit, then a client did leave a hall at the informed time; and if a card describes an unknown event, then a client did enter or leave a hall at the informed time.

The last test case is followed by a line containing a single zero.

Output

For each test case in the input, your program must print a single line, containing one single integer, the maximum total number of clients that could have been inside the dinner halls in a given instant of time.

Sample Input

4 
07:22:03 X
07:13:22 E
08:30:51 E
21:59:02 X
4 
09:00:00 E
20:00:01 X
09:05:00 ?
20:00:00 ?
8 
10:21:00 E
10:25:00 X
10:23:00 E
10:24:00 X
10:26:00 X
10:27:00 ?
10:22:00 ?
10:20:00 ?
0

Sample Output

1 
2 
4

代码重写了一遍,用的vector

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int max(int a,int b)
{
	if(a>b)
		return a;
	else
		return b;
}

class student
{
	public:
		int s;
		char t;
};

bool cmp(student a,student b)
{
	return a.s < b.s;
}

bool isentry(student n) 
{ 
	if(n.t=='E')
		return true;
	else
		return false;
}
bool isexit(student n) 
{ 
	if(n.t=='X')
		return true;
	else
		return false;
}
bool isunknown(student n) 
{ 
	if(n.t=='?')
		return true;
	else 
		return false;
}

vector<student> dinner;

int main()
{
	int testcase;
	while(cin>>testcase && testcase!=0)
	{
		int jin=0,chu=0,unknown=0;
		int hour,min,sec;
		char tmp,t;
		dinner.clear();
		for(int i=0;i<testcase;i++)
		{
			student needin;
			cin>>hour>>tmp>>min>>tmp>>sec>>t;
			needin.s=hour*3600+min*60+sec;
			needin.t=t;
			if(isentry(needin))
				jin++;
			if(isexit(needin))
				chu++;
			if(isunknown(needin))
				unknown++;
			
			dinner.push_back(needin);
		}
		sort(dinner.begin(),dinner.end(),cmp);
		
		int maxin = (unknown-(jin-chu))/2;
		
		int currentin=0;
		int currmax=0;
		for(int i=0;i<dinner.size();i++)
		{
			if(isentry(dinner[i]))
				currentin++;
			if(isexit(dinner[i]))
				currentin--;
			if(isunknown(dinner[i]))
			{
				if(maxin!=0)
				{
					currentin++;
					maxin--;
				}
				else
					currentin--;
			}
			currmax=max(currmax,currentin);	
			
		}
		cout<<currmax<<endl;
		
	}
	
	return 0;
}


内容概要:本文系统阐述了Java Persistence API(JPA)的核心概念、技术架构、核心组件及实践应用,重点介绍了JPA作为Java官方定义的对象关系映射(ORM)规范,如何通过实体类、EntityManager、JPQL和persistence.xml配置文件实现Java对象与数据库表之间的映射与操作。文章详细说明了JPA解决的传统JDBC开发痛点,如代码冗余、对象映射繁琐、跨数据库兼容性差等问题,并解析了JPA与Hibernate、EclipseLink等实现框架的关系。同时提供了基于Hibernate和MySQL的完整实践案例,涵盖Maven依赖配置、实体类定义、CRUD操作实现等关键步骤,并列举了常用JPA注解及其用途。最后总结了JPA的标准化优势、开发效率提升能力及在Spring生态中的延伸应用。 适合人群:具备一定Java基础,熟悉基本数据库操作,工作1-3年的后端开发人员或正在学习ORM技术的中级开发者。 使用场景及目标:①理解JPA作为ORM规范的核心原理与组件协作机制;②掌握基于JPA+Hibernate进行数据库操作的开发流程;③为技术选型、团队培训或向Spring Data JPA过渡提供理论与实践基础。 阅读建议:此资源以理论结合实践的方式讲解JPA,建议读者在学习过程中同步搭建环境,动手实现文中示例代码,重点关注EntityManager的使用、JPQL语法特点以及注解配置规则,从而深入理解JPA的设计思想与工程价值。
先看效果: https://pan.quark.cn/s/d787a05b82eb 西门子SCALANCE X系列交换机是西门子公司所提供的工业以太网交换机产品系列,其在工业自动化领域具有广泛的应用。 如果在应用期间遭遇固件升级失误或采用了不相容的固件版本,可能会导致交换机无法正常启动。 在这种情况下,通常能够借助FTP(文件传输协议)来恢复交换机的固件,从而使其恢复正常运作。 本文件详细阐述了利用FTP修复SCALANCE X系列交换机固件的方法,并具体说明了实施步骤。 当SCALANCE X系列交换机的固件出现故障时,设备在启动后会自动激活引导加载程序,并通过故障LED的闪烁来表明设备处于特殊情形。 在这种情形下,交换机能够充当FTP服务器,与客户端建立联系,执行固件数据的传输。 需要特别强调的是,对于SCALANCE X200系列交换机,必须经由端口1来连接FTP客户端。 在实施步骤方面,首先需要为交换机指定一个IP地址。 这一步骤通常借助西门子公司提供的PST(Product Support Tools)软件来实施。 在成功配置IP地址之后,就可以通过FTP协议与交换机内部的FTP服务器建立连接,并借助FTP客户端将固件文件传输到交换机。 需要留意的是,在传输固件文件之前,应当先从西门子技术支持网站获取对应订货号的固件版本文件。 一旦固件文件备妥,就可以开始FTP操作。 这通常涉及打开操作系统的DOS窗口,运用FTP指令连接到交换机的FTP服务器,并输入正确的用户名和密码进行身份验证。 在本案例中,用户名和密码均为“siemens”,并且传输模式设定为二进制。 随后,使用FTP的“put”指令将本地固件文件上传至交换机。 值得留意的是,固件文件名必须严格遵循大小写规则。 上传成功后,...
源码地址: https://pan.quark.cn/s/f24fc84966ae 人机交互在电子工程领域中占据着核心地位,它具体指的是单片机系统与用户之间进行信息交换和管理操作的方法。 在此过程中,单片机系统负责接收用户的输入信号,对收集到的信息进行加工处理,并通过特定媒介将处理结果呈现给用户,这些媒介包括但不限于显示器、LED指示灯以及蜂鸣器等设备。 在本探讨的主题中,我们将重点研究按键与1602液晶显示屏之间的交互机制。 1602液晶显示屏是单片机应用领域中一种极为常见的人机交互界面设备,其功能在于能够显示两行文本,每行包含16个字符。 此类显示器通常采用串行或并行接口与单片机设备进行连接,主要用途是展示程序运行的状态信息、数据读取的最终结果以及其他相关的重要资讯。 我们需要深入理解如何对1602液晶显示屏进行配置和控制。 这一过程通常涉及到初始化序列的执行,其中包括设定显示模式(例如开启/关闭状态、光标移动的方向以及是否启用闪烁效果),同时选择合适的数据传输方式(4线或8线模式)。 单片机系统必须向液晶显示屏发送特定的指令集,以此来设定上述参数。 举例来说,可以通过RS(寄存器选择)、RW(读写信号)以及E(使能)引脚与LCD设备进行通信。 接下来,我们将详细讨论按键接口的设计方案。 按键通常作为输入设备存在,允许用户向单片机系统发送指令或数据。 在单片机系统中,按键通常与IO端口相连接,通过检测IO端口电平的变化来判断按键是否被触发。 对于基础的按键应用场景,可能仅需检测按键闭合时产生的低电平信号;而对于更为复杂的应用场景,则可能需要处理消抖问题,以防止因机械接触产生的瞬间抖动导致错误的读数。 在Proteus软件环境中,我们可以构建虚拟的电路模型来模拟单片机系统,其中包括1...
数据集介绍:垃圾分类检测数据集 一、基础信息 数据集名称:垃圾分类检测数据集 图片数量: 训练集:2,817张图片 验证集:621张图片 测试集:317张图片 总计:3,755张图片 分类类别: - 金属:常见的金属垃圾材料。 - 纸板:纸板类垃圾,如包装盒等。 - 塑料:塑料类垃圾,如瓶子、容器等。 标注格式: YOLO格式,包含边界框和类别标签,适用于目标检测任务。 数据格式:图片来源于实际场景,格式为常见图像格式(如JPEG/PNG)。 二、适用场景 智能垃圾回收系统开发: 数据集支持目标检测任务,帮助构建能够自动识别和分类垃圾材料的AI模型,用于自动化废物分类和回收系统。 环境监测与废物管理: 集成至监控系统或机器人中,实时检测垃圾并分类,提升废物处理效率和环保平。 学术研究与教育: 支持计算机视觉与环保领域的交叉研究,用于教学、实验和论文发表。 三、数据集优势 类别覆盖全面: 包含三种常见垃圾材料类别,覆盖日常生活中主要的可回收物类型,具有实际应用价值。 标注精准可靠: 采用YOLO标注格式,边界框定位精确,类别标签准确,便于模型直接训练和使用。 数据量适中合理: 训练集、验证集和测试集分布均衡,提供足够样本用于模型学习和评估。 任务适配性强: 标注兼容主流深度学习框架(如YOLO等),可直接用于目标检测任务,支持垃圾检测相关应用。
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值