301479: CF279A. Point on Spiral

Memory Limit:256 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Point on Spiral

题意翻译

在平面上,有一个螺旋,由线段 $[(0,0)(1,0)]$、$[(1,0)(1,1)]$、$[(1,1)(-1,1)]$、$[(-1,1)(-1,-1)]$、$[(-1,-1)(2,-1)]$、$[(2,-1)(2,2)]$、$\cdots$ 组成。问:从点 $(0,0)$ 沿螺旋走到点 $(x,y)$ 需要转几次弯?

题目描述

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

输入输出格式

输入格式


The first line contains two space-separated integers $ x $ and $ y $ $ (|x|,|y|<=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

Input

题意翻译

在平面上,有一个螺旋,由线段 $[(0,0)(1,0)]$、$[(1,0)(1,1)]$、$[(1,1)(-1,1)]$、$[(-1,1)(-1,-1)]$、$[(-1,-1)(2,-1)]$、$[(2,-1)(2,2)]$、$\cdots$ 组成。问:从点 $(0,0)$ 沿螺旋走到点 $(x,y)$ 需要转几次弯?

加入题单

算法标签: