B. Odd Grasshopper
The grasshopper is located on the numeric axis at the point with
coordinate x0.Having nothing else to do he starts jumping between integer points on
the axis. Making a jump from a point with coordinate x with a distance
d to the left moves the grasshopper to a point with a coordinate x−d,
while jumping to the right moves him to a point with a coordinate x+d.The grasshopper is very fond of positive integers, so for each integer
i starting with 1 the following holds: exactly i minutes after the
start he makes a jump with a distance of exactly i. So, in the first
minutes he jumps by 1, then by 2, and so on.The direction of a jump is determined as follows: if the point where
the grasshopper was before the jump has an even coordinate, the
grasshopper jumps to the left, otherwise he jumps to the right.For example, if after 18 consecutive jumps he arrives at the point
with a coordinate 7, he will jump by a distance of 19 to the right,
since 7 is an odd number, and will end up at a point 7+19=26. Since 26
is an even number, the next jump the grasshopper will make to the left
by a distance of 20, and it will move him to the point 26−20=6.Find exactly which point the grasshopper will be at after exactly n
jumps.
题意:奇数跳后,偶数跳前,且跳的值都是当前第n次的n,求从a开始跳n次的坐标在哪里
思路: 演练一遍就会发现,这道题完全就是一个以4为一次循环而不断递增(至今不懂为什么这道题我做了一个小时 屮)
代码:

这篇博客讨论了'codeforces B. Odd Grasshopper'问题,描述了一只蚱蜢在数轴上根据坐标奇偶性进行跳跃的规则。蚱蜢每分钟跳跃的步长等于当前的分钟数,奇数分钟向左跳,偶数分钟向右跳。文章通过示例解释了跳跃过程,并提供了解决问题的思路和代码。
最低0.47元/天 解锁文章
562

被折叠的 条评论
为什么被折叠?



