CF279A.Point on Spiral

普及/提高-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

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).

马瓦莱拉生活在平面上。该平面上定义了笛卡尔坐标系。此外,平面上还绘制了一条无限螺旋线。该螺旋线由如下线段组成:
[(0, 0), (1, 0)], [(1, 0), (1, 1)], [(1, 1), ( - 1, 1)], [( - 1, 1), ( - 1,  - 1)], [( - 1,  - 1), (2,  - 1)], [(2,  - 1), (2, 2)],依此类推。因此,这条无限螺旋线经过平面上的每一个整数坐标点。

马瓦莱拉生活在坐标为 (0, 0) 的平面上。他希望沿着螺旋线从点 (0, 0) 走到点 (x, y)。由于瓦莱拉有四条腿,转弯对他而言非常困难。请计算:若他沿螺旋线从点 (0, 0) 走到点 (x, y),总共需要转弯多少次。

输入格式

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

第一行包含两个以空格分隔的整数 xx 和 yy(∣x∣, ∣y∣ ≤ 100|x|, |y| \le 100)。

输出格式

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

输出一个整数,表示瓦列拉需要转弯的次数。

输入输出样例

  • 输入#1

    0 0

    输出#1

    0
  • 输入#2

    1 0

    输出#2

    0
  • 输入#3

    0 1

    输出#3

    2
  • 输入#4

    -1 -1

    输出#4

    3

输入解题思路,AI测评打分。不知道怎么写?

首页