310242: CF1804A. Lame King
Description
You are given a checkerboard of size $201 \times 201$, i. e. it has $201$ rows and $201$ columns. The rows of this checkerboard are numbered from $-100$ to $100$ from bottom to top. The columns of this checkerboard are numbered from $-100$ to $100$ from left to right. The notation $(r, c)$ denotes the cell located in the $r$-th row and the $c$-th column.
There is a king piece at position $(0, 0)$ and it wants to get to position $(a, b)$ as soon as possible. In this problem our king is lame. Each second, the king makes exactly one of the following five moves.
- Skip move. King's position remains unchanged.
- Go up. If the current position of the king is $(r, c)$ he goes to position $(r + 1, c)$.
- Go down. Position changes from $(r, c)$ to $(r - 1, c)$.
- Go right. Position changes from $(r, c)$ to $(r, c + 1)$.
- Go left. Position changes from $(r, c)$ to $(r, c - 1)$.
What is the minimum number of seconds the lame king needs to reach position $(a, b)$?
InputThe first line of the input contains a single integer $t$ ($1 \leq t \leq 10^4$) — the number of test cases. Then follow $t$ lines containing one test case description each.
Each test case consists of two integers $a$ and $b$ ($-100 \leq a, b \leq 100$) — the position of the cell that the king wants to reach. It is guaranteed that either $a \ne 0$ or $b \ne 0$.
OutputPrint $t$ integers. The $i$-th of these integers should be equal to the minimum number of seconds the lame king needs to get to the position he wants to reach in the $i$-th test case. The king always starts at position $(0, 0)$.
ExampleInput5 -4 1 4 4 0 -6 -5 -4 7 -8Output
7 8 11 9 15Note
One of the possible solutions for the first example is: go down, go right, go down, go right, go down, go left, go down.
One of the possible solutions for the second example is to alternate "go right" and "go up" moves $4$ times each.
One of the possible solutions for the third example is to alternate "go left" and "skip" moves starting with "go left". Thus, "go left" will be used $6$ times, and "skip" will be used $5$ times.
Input
题意翻译
有一个 $201 \times 201$ 的格子,下标 $-100 \leq x,y \leq 100$。$t(t \leq 10^4)$ 组数据,每组数据给你 $x$ 和 $y$,问从 $(0,0)$ 走到 $(x,y)$ 至少需要几步(每次能向上,下,左,右是个方向走,但不能超过格子边界,并且连续两步的操作不能相同)。Output
在一个201x201的棋盘上,行号从-100到100,列号也是从-100到100。有一个棋子位于(0,0),目标是在最短时间内到达(a,b)。棋子每次移动可以选择五种动作之一:跳过、上移、下移、右移、左移。但不能连续两步走相同的方向,也不能走出棋盘边界。求棋子到达目标位置的最短时间。
输入输出数据格式:
输入:
第一行是一个整数t(1≤t≤10^4),表示测试用例的数量。
接下来t行,每行包含两个整数a和b(-100≤a,b≤100),表示棋子要到达的目标位置。保证a和b至少有一个不为0。
输出:
输出t个整数,第i个整数表示第i个测试用例中,棋子到达目标位置所需的最短时间。
示例:
输入:
5
-4 1
4 4
0 -6
-5 -4
7 -8
输出:
7
8
11
9
15题目大意: 在一个201x201的棋盘上,行号从-100到100,列号也是从-100到100。有一个棋子位于(0,0),目标是在最短时间内到达(a,b)。棋子每次移动可以选择五种动作之一:跳过、上移、下移、右移、左移。但不能连续两步走相同的方向,也不能走出棋盘边界。求棋子到达目标位置的最短时间。 输入输出数据格式: 输入: 第一行是一个整数t(1≤t≤10^4),表示测试用例的数量。 接下来t行,每行包含两个整数a和b(-100≤a,b≤100),表示棋子要到达的目标位置。保证a和b至少有一个不为0。 输出: 输出t个整数,第i个整数表示第i个测试用例中,棋子到达目标位置所需的最短时间。 示例: 输入: 5 -4 1 4 4 0 -6 -5 -4 7 -8 输出: 7 8 11 9 15