CF2147A.Shortest Increasing Path
入门
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You are at (0,0) in a rectangular grid and want to go to (x,y).
In order to do so, you are allowed to perform a sequence of steps.
Each step consists of moving a positive integer amount of length in the positive direction of either the x or the y axis.
The first step must be along the x axis, the second along the y axis, the third along the x axis, and so on. Formally, if we number steps from one in the order they are done, then odd-numbered steps must be along the x axis and even-numbered steps must be along the y axis.
Additionally, each step must have a length strictly greater than the length of the previous one.
Output the minimum number of steps needed to reach (x,y), or −1 if it is impossible.
你位于矩形网格中的点 (0,0),目标是到达点 (x,y)。
为此,你可以执行一系列移动步骤。
每一步必须沿 x 轴或 y 轴的正方向移动一个正整数长度。
第一步必须沿 x 轴,第二步沿 y 轴,第三步沿 x 轴,依此类推。形式化地说,若将步骤按执行顺序从 1 开始编号,则奇数编号的步骤必须沿 x 轴,偶数编号的步骤必须沿 y 轴。
此外,每一步的长度必须严格大于前一步的长度。
输出到达 (x,y) 所需的最少步数;若无法到达,则输出 −1。
输入格式
Each test contains multiple test cases. The first line contains the number of test cases t (1≤t≤104). The description of the test cases follows.
The first and only line of each case contains two integers x and y (1≤x,y≤109).
每个测试包含多个测试用例。第一行包含测试用例的数量 t(1≤t≤104)。随后是各测试用例的描述。
每个测试用例仅有一行,包含两个整数 x 和 y(1≤x,y≤109)。
输出格式
For each test case, output the minimum number of steps to reach (x,y) or −1 if it is impossible.
对于每个测试用例,输出到达 (x,y) 所需的最少步数;如果无法到达,则输出 −1。
输入输出样例
输入#1
10 1 2 5 6 4 2 1 1 2 1 3 3 5 1 5 4 752 18572 95152 2322
输出#1
2 2 3 -1 -1 -1 -1 -1 2 3
说明/提示
In the second test case, you can move to (5,0) by moving 5 along the x axis and then to (5,6) by moving 6 along the y axis.

In the third test case, you can move to (1,0), then to (1,2), and finally to (4,2).

In the fourth test case, reaching (1,1) is impossible since after moving to (1,0) along the x axis, you are forced to move at least 2 along the y axis.
在第二个测试用例中,你可以先沿 x 轴移动 5 个单位到达 (5,0),再沿 y 轴移动 6 个单位到达 (5,6)。

在第三个测试用例中,你可以先移动到 (1,0),再移动到 (1,2),最后移动到 (4,2)。

在第四个测试用例中,无法到达 (1,1),因为沿 x 轴移动到 (1,0) 后,你必须至少沿 y 轴移动 2 个单位。
输入解题思路,AI测评打分。不知道怎么写?