Point on Spiral CodeForces - 279A

博客内容概述:这篇博客讨论了平面直角坐标系中的一条无限螺旋路径,它经过所有整数点。马Valera从原点出发,想要沿着这条螺旋路径走到点(x, y)。由于马有四条腿,转弯比较困难。博客提供了输入x和y的值,计算Valera在到达(x, y)过程中需要转弯的次数。" 82910356,7816798,K-means聚类:如何选择最佳k值,"['数据挖掘', '机器学习', '聚类分析', 'K-means算法']
摘要由CSDN通过智能技术生成

Valera the horse lives on a plane. The Cartesian coordinate system is defined on this plane. Also an infinite spiral is painted on the plane. The spiral consists of segments: [(0, 0), (1, 0)], [(1, 0), (1, 1)], [(1, 1), ( - 1, 1)], [( - 1, 1), ( - 1,  - 1)], [( - 1,  - 1), (2,  - 1)], [(2,  - 1), (2, 2)] and so on. Thus, this infinite spiral passes through each integer point of the plane.

Valera the horse lives on the plane at coordinates (0, 0). He wants to walk along the spiral to point (x, y). Valera the horse has four legs, so he finds turning very difficult. Count how many times he will have to turn if he goes along a spiral from point (0, 0) to point (x, y).

Input
The first line contains two space-separated integers x and y (|x|, |y| ≤ 100).

Output
Print a single integer, showing how many times Valera has to turn.

#include <cstdio&g
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值