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

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

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

链接:点击打开链接,密码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;
}


内容概要:本文介绍了多种开发者工具及其对开发效率的提升作用。首先,介绍了两款集成开发环境(IDE):IntelliJ IDEA 以其智能代码补全、强大的调试工具和项目管理功能适用于Java开发者;VS Code 则凭借轻量级和多种编程语言的插件支持成为前端开发者的常用工具。其次,提到了基于 GPT-4 的智能代码生成工具 Cursor,它通过对话式编程显著提高了开发效率。接着,阐述了版本控制系统 Git 的重要性,包括记录代码修改、分支管理和协作功能。然后,介绍了 Postman 作为 API 全生命周期管理工具,可创建、测试和文档化 API,缩短前后端联调时间。再者,提到 SonarQube 这款代码质量管理工具,能自动扫描代码并检测潜在的质量问题。还介绍了 Docker 容器化工具,通过定义应用的运行环境和依赖,确保环境一致性。最后,提及了线上诊断工具 Arthas 和性能调优工具 JProfiler,分别用于生产环境排障和性能优化。 适合人群:所有希望提高开发效率的程序员,尤其是有一定开发经验的软件工程师和技术团队。 使用场景及目标:①选择合适的 IDE 提升编码速度和代码质量;②利用 AI 编程助手加快开发进程;③通过 Git 实现高效的版本控制和团队协作;④使用 Postman 管理 API 的全生命周期;⑤借助 SonarQube 提高代码质量;⑥采用 Docker 实现环境一致性;⑦运用 Arthas 和 JProfiler 进行线上诊断和性能调优。 阅读建议:根据个人或团队的需求选择适合的工具,深入理解每种工具的功能特点,并在实际开发中不断实践和优化。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值