POJ 1006 Biorhythms Writeup

本文介绍了一道关于生物周期的问题,探讨了如何计算个人生命中三种周期(体能、情感和智力)的峰值同时出现的日子。通过分析问题背景及输入输出要求,给出了一个简单直接的解决方案,并提及了更高效的解决方法——中国剩余定理。

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

Biorhythms
Time Limit: 1000MS Memory Limit: 10000K
Total Submissions: 143601 Accepted: 46190

Description

Some people believe that there are three cycles in a person's life that start the day he or she is born. These three cycles are the physical, emotional, and intellectual cycles, and they have periods of lengths 23, 28, and 33 days, respectively. There is one peak in each period of a cycle. At the peak of a cycle, a person performs at his or her best in the corresponding field (physical, emotional or mental). For example, if it is the mental curve, thought processes will be sharper and concentration will be easier. 
Since the three cycles have different periods, the peaks of the three cycles generally occur at different times. We would like to determine when a triple peak occurs (the peaks of all three cycles occur in the same day) for any person. For each cycle, you will be given the number of days from the beginning of the current year at which one of its peaks (not necessarily the first) occurs. You will also be given a date expressed as the number of days from the beginning of the current year. You task is to determine the number of days from the given date to the next triple peak. The given date is not counted. For example, if the given date is 10 and the next triple peak occurs on day 12, the answer is 2, not 3. If a triple peak occurs on the given date, you should give the number of days to the next occurrence of a triple peak. 

Input

You will be given a number of cases. The input for each case consists of one line of four integers p, e, i, and d. The values p, e, and i are the number of days from the beginning of the current year at which the physical, emotional, and intellectual cycles peak, respectively. The value d is the given date and may be smaller than any of p, e, or i. All values are non-negative and at most 365, and you may assume that a triple peak will occur within 21252 days of the given date. The end of input is indicated by a line in which p = e = i = d = -1.

Output

For each test case, print the case number followed by a message indicating the number of days to the next triple peak, in the form: 

Case 1: the next triple peak occurs in 1234 days. 

Use the plural form ``days'' even if the answer is 1.

Sample Input

0 0 0 0
0 0 0 100
5 20 34 325
4 5 6 7
283 102 23 320
203 301 203 40
-1 -1 -1 -1

Sample Output

Case 1: the next triple peak occurs in 21252 days.
Case 2: the next triple peak occurs in 21152 days.
Case 3: the next triple peak occurs in 19575 days.
Case 4: the next triple peak occurs in 16994 days.
Case 5: the next triple peak occurs in 8910 days.
Case 6: the next triple peak occurs in 10789 days.

Source

翻译

生物周期

有的人相信每个人一出生就有着三个个循环伴随着他的一生。这三个循环分别是体能周期,情感周期和智力周期,这三个周期的时长又分别是23,28和33天。在每一个周期里会出现相应的巅峰。在巅峰期内,一个人在相应的领域(体能、情感或智力)内表现会达到最佳。例如,当达到了智力曲线的峰值,思维会变得更加敏锐并且注意力更为集中。

由于三种循环的周期长度不同,三个峰值通常也发生在不同的时期。现在我们想要确定一个人何时会出现三重巅峰(三种循环的巅峰发生于同一天)。你会得到每一个循环在今年的三重巅峰出现的日期(不一定是第一个三重巅峰)。你还会得到一个表示今年开始的日期。你的任务是确定从开始日期到下一个三重巅峰的天数。所给出的开始天数并不被计算在内。例如,如果给出的日期是10并且下一个三重巅峰发生的日期12。答案就是2,而不是3。如果有一个三重巅峰在所给出的日期发生,那么你需要给出距离下一个三重巅峰发生的天数。

输入

你会得到数种情况。对于每一种情况包括四个整数p、e、i和d。p、e、i的值分别代表三种循环在今年出现的一个巅峰时期。d的值代表所给出的开始日期并且可能小于p、e、i其中任意一个。输入的末尾将是p = e = i = d = -1。

输出

对于每一个试验情况,请在屏幕上以如下形式输出是第几种情况,并指出距离下一个三重巅峰的天数。

情况1:下一个三重巅峰将出现在1234天后。

即使答案是1也请使用day的复数形式“days”

样例输入

0 0 0 0
0 0 0 100
5 20 34 325
4 5 6 7
283 102 23 320
203 301 203 40
-1 -1 -1 -1

样例输出

Case 1: the next triple peak occurs in 21252 days.
Case 2: the next triple peak occurs in 21152 days.
Case 3: the next triple peak occurs in 19575 days.
Case 4: the next triple peak occurs in 16994 days.
Case 5: the next triple peak occurs in 8910 days.
Case 6: the next triple peak occurs in 10789 days.


解题思路

从所给天数开始一天一天找下一个三重巅峰出现的日期,并不算什么聪明的方法吧。

注意点

要注意一下边界条件吧,得从所给日期的下一天开始找。

对比

大佬们都用的中国剩余定理来计算,只有O(1)的时间复杂度,不过感觉有点难理解,还是我太菜了。。

/*
	Memory:184K
	Time:735MS
*/


#include <cstdio>
#include <cstdlib>
using namespace std;


int main()
{
	int p=0,e=0,i=0,d=0,kase=1;
	while(scanf("%d %d %d %d",&p,&e,&i,&d)==4&&p!=-1)
	{
		for(int n=d+1;;n++)
		{
			if((abs(p-n)%23==0)&&(abs(e-n)%28==0)&&(abs(i-n)%33==0))
			{
				printf("Case %d: the next triple peak occurs in %d days.\n",kase++,n-d);
				break;
			}
		}
	}
	return 0;
}

内容概要:本文档详细介绍了基于MATLAB实现的无人机三维路径规划项目,核心算法采用蒙特卡罗树搜索(MCTS)。项目旨在解决无人机在复杂三维环境中自主路径规划的问题,通过MCTS的随机模拟与渐进式搜索机制,实现高效、智能化的路径规划。项目不仅考虑静态环境建模,还集成了障碍物检测与避障机制,确保无人机飞行的安全性和效率。文档涵盖了从环境准备、数据处理、算法设计与实现、模型训练与预测、性能评估到GUI界面设计的完整流程,并提供了详细的代码示例。此外,项目采用模块化设计,支持多无人机协同路径规划、动态环境实时路径重规划等未来改进方向。 适合人群:具备一定编程基础,特别是熟悉MATLAB和无人机技术的研发人员;从事无人机路径规划、智能导航系统开发的工程师;对MCTS算法感兴趣的算法研究人员。 使用场景及目标:①理解MCTS算法在三维路径规划中的应用;②掌握基于MATLAB的无人机路径规划项目开发全流程;③学习如何通过MCTS算法优化无人机在复杂环境中的飞行路径,提高飞行安全性和效率;④为后续多无人机协同规划、动态环境实时调整等高级应用打下基础。 其他说明:项目不仅提供了详细的理论解释和技术实现,还特别关注了实际应用中的挑战和解决方案。例如,通过多阶段优化与迭代增强机制提升路径质量,结合环境建模与障碍物感知保障路径安全,利用GPU加速推理提升计算效率等。此外,项目还强调了代码模块化与调试便利性,便于后续功能扩展和性能优化。项目未来改进方向包括引入深度强化学习辅助路径规划、扩展至多无人机协同路径规划、增强动态环境实时路径重规划能力等,展示了广阔的应用前景和发展潜力。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值