codeforces B. Odd Grasshopper

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为一次循环而不断递增(至今不懂为什么这道题我做了一个小时 屮)

代码:


                
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值