CF1452A.Robot Program

入门

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

There is an infinite 2-dimensional grid. The robot stands in cell (0,0)(0, 0) and wants to reach cell (x,y)(x, y). Here is a list of possible commands the robot can execute:

  • move north from cell (i,j)(i, j) to (i,j+1)(i, j + 1);
  • move east from cell (i,j)(i, j) to (i+1,j)(i + 1, j);
  • move south from cell (i,j)(i, j) to (i,j−1)(i, j - 1);
  • move west from cell (i,j)(i, j) to (i−1,j)(i - 1, j);
  • stay in cell (i,j)(i, j).

The robot wants to reach cell (x,y)(x, y) in as few commands as possible. However, he can't execute the same command two or more times in a row.

What is the minimum number of commands required to reach (x,y)(x, y) from (0,0)(0, 0)?

存在一个无限的二维网格。机器人位于单元格 (0,0)(0, 0),希望到达单元格 (x,y)(x, y)。以下是机器人可执行的指令列表:

  • 向北移动:从单元格 (i,j)(i, j) 移动到 (i,j+1)(i, j + 1);
  • 向东移动:从单元格 (i,j)(i, j) 移动到 (i+1,j)(i + 1, j);
  • 向南移动:从单元格 (i,j)(i, j) 移动到 (i,j−1)(i, j - 1);
  • 向西移动:从单元格 (i,j)(i, j) 移动到 (i−1,j)(i - 1, j);
  • 停留在单元格 (i,j)(i, j)。

机器人希望以尽可能少的指令数到达 (x,y)(x, y)。然而,它不能连续两次或更多次执行相同的指令。

从 (0,0)(0, 0) 到达 (x,y)(x, y) 所需的最少指令数是多少?

输入格式

The first line contains a single integer tt (1≤t≤1001 \le t \le 100) — the number of testcases.

Each of the next tt lines contains two integers xx and yy (0≤x,y≤1040 \le x, y \le 10^4) — the destination coordinates of the robot.

第一行包含一个整数 tt(1≤t≤1001 \le t \le 100)——测试用例的数量。

接下来的 tt 行中,每行包含两个整数 xx 和 yy(0≤x,y≤1040 \le x, y \le 10^4)——机器人的目标坐标。

输出格式

For each testcase print a single integer — the minimum number of commands required for the robot to reach (x,y)(x, y) from (0,0)(0, 0) if no command is allowed to be executed two or more times in a row.

对于每个测试用例,输出一个整数——机器人从 (0,0)(0, 0) 到达 (x,y)(x, y) 所需的最少指令数,且不允许任何指令连续执行两次或以上。

输入输出样例

  • 输入#1

    5
    5 5
    3 4
    7 1
    0 0
    2 0

    输出#1

    10
    7
    13
    0
    3

说明/提示

The explanations for the example test:

We use characters N, E, S, W and 0 to denote going north, going east, going south, going west and staying in the current cell, respectively.

In the first test case, the robot can use the following sequence: NENENENENE.

In the second test case, the robot can use the following sequence: NENENEN.

In the third test case, the robot can use the following sequence: ESENENE0ENESE.

In the fourth test case, the robot doesn't need to go anywhere at all.

In the fifth test case, the robot can use the following sequence: E0E.

示例测试的解释:

我们使用字符 N、E、S、W 和 0 分别表示向北移动、向东移动、向南移动、向西移动以及停留在当前格子。

在第一个测试用例中,机器人可采用如下序列:NENENENENE。

在第二个测试用例中,机器人可采用如下序列:NENENEN。

在第三个测试用例中,机器人可采用如下序列:ESENENE0ENESE。

在第四个测试用例中,机器人完全无需移动。

在第五个测试用例中,机器人可采用如下序列:E0E。

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

首页