Robot Program
题目链接:https://codeforces.com/problemset/problem/1452/A
题目描述:
There is an infinite 2-dimensional grid. The robot stands in cell (0,0) and wants to reach cell (x,y). Here is a list of possible commands the robot can execute:
move north from cell (i,j) to (i,j+1);
move east from cell (i,j) to (i+1,j);
move south from cell (i,j) to (i,j−1);
move west from cell (i,j) to (i−1,j);
stay in cell (i,j).
The robot wants to reach cell (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) from (0,0)?
描述翻译:
有一个无限的二维网格。机器人站在单元格(0,0)中,想要到达单元格(x,y)。以下是机器人可以执行的命令列表:
从单元格(i,j) 向北移动到(i,j+1);
从单元格(i,j) 向东移动到(i+1,j);
从单元(i,j) 向南移动到(i,j−1);
从单元格(i,j) 向西移动到(i−1,j);
待在当前的单元格中。
机器人想用尽可能少的命令到达单元格(x,y)。但他不能在同一行中执行两次或更多次。
从(0,0)到达(x,y)所需的最小命令数是多少?
输入:
The first line contains a single integer t (1≤t≤100) — the number of testcases.
Each of the next t lines contains two integers x and y (0≤x,y≤104) — the destination coordinates of the robot.
机器人程序题解:找规律求最短命令数

博客围绕机器人程序题目展开,机器人在二维网格从(0,0)到(x,y),不能连续执行相同命令,求最少命令数。题解指出不能用深搜广搜,应找规律,x==y时向下向右交替,x!=y时先算最小值,再停一下走一下,终点不停减一。
最低0.47元/天 解锁文章
522

被折叠的 条评论
为什么被折叠?



