Logo
(追記) (追記ここまで)

32048번 - Honeycomb Distance 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
8 초 (추가 시간 없음) 1024 MB1521157884.783%

문제

A plane is tiled completely with regular hexagons. Each hexagon is called a cell. You can move in one step from a cell to one of its adjacent cells that share an edge. You want to know the minimum number of steps to move from the central cell to the specified cell.

Each cell is specified by a pair of integers. The central cell is (0, 0). One of the directions perpendicular to the edges of the regular hexagons is defined to be the rightward direction. For each cell (x, y), its right adjacent cell is (x + 1, y) and its upper-right adjacent cell is (x, y + 1). See the figure below.

Write a program that computes the minimum number of steps required to move from the cell (0, 0) to the cell (x, y) for given integers x and y.

Figure C-1: How to specify the cells

입력

The first line of the input contains only one positive integer n, which is the number of datasets. n does not exceed 100. Each of the following n lines contains one dataset.

Each dataset consists of two integers x and y, which satisfy −1000 ≤ x ≤ 1000 and −1000 ≤ y ≤ 1000. The destination cell is (x, y).

출력

For each dataset, output one line containing the minimum number of steps required to move from the cell (0, 0) to the destination cell.

제한

예제 입력 1

7
0 0
0 1
1 0
2 1
2 -1
-3 2
-1 -3

예제 출력 1

0
1
1
3
2
3
4

힌트

출처

ICPC > Regionals > Asia Pacific > Japan > Japan Domestic Contest > 2024 Japan Domestic Contest C번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /