编程题:22
T = int(input())
初始化乌龟和兔子的距离、兔子的时间统计及休息标记
turtle_distance = T * 3
rabbit_distance = 0
rabbit_time = 0
resting = False
rest_time = 0
while rabbit_time < T:
if not resting:
# 兔子跑 10 分钟阶段
run_duration = min(10, T - rabbit_time)
rabbit_distance += run_duration * 9
rabbit_time += run_duration
# 检查是否超过乌龟,这里乌龟在 rabbit_time 分钟内跑的距离是 rabbit_time * 3(因为乌龟一直跑)
turtle_current = rabbit_time * 3
if rabbit_distance > turtle_current:
resting = True
rest_time = 30
else:
# 兔子休息阶段
rest_duration = min(rest_time, T - rabbit_time)
rabbit_time += rest_duration
rest_time -= rest_duration
if rest_time == 0:
resting = False
比较两者距离
if turtle_distance > rabbit_distance:
print(f"@@ {turtle_distance}")
elif turtle_distance < rabbit_distance:
print(f"_ {rabbit_distance}")
else:
print(f"-- {turtle_distance}")
浙公网安备 33010602011771号