#abc271h. Ex - General General
Ex - General General
Score : points
问题描述
为 个测试用例求解以下问题。
一块棋子位于 平面上的原点 。你可以执行任意次数(包括零次)以下操作:
- 选择一个整数 ,满足 且
1
。设 为当前棋子所在的坐标位置。- 若 ,将棋子移动到 。
- 若 ,将棋子移动到 。
- 若 ,将棋子移动到 。
- 若 ,将棋子移动到 。
- 若 ,将棋子移动到 。
- 若 ,将棋子移动到 。
- 若 ,将棋子移动到 。
- 若 ,将棋子移动到 。
你的目标是将棋子移动到坐标点 。
找出实现该目标所需的最少操作次数。如果无法实现,则输出 -1
。
以上为通义千问 qwen-max 翻译,仅供参考。
Problem Statement
Solve the following problem for test cases.
A piece is placed at the origin on an -plane. You may perform the following operation any number of (possibly zero) times:
- Choose an integer such that and
1
. Let be the current coordinates where the piece is placed.- If , move the piece to .
- If , move the piece to .
- If , move the piece to .
- If , move the piece to .
- If , move the piece to .
- If , move the piece to .
- If , move the piece to .
- If , move the piece to .
Your objective is to move the piece to .
Find the minimum number of operations needed to achieve the objective. If it is impossible, print -1
instead.
Constraints
- is
0
or1
. - , , and are integers.
Input
The input is given from Standard Input in the following format:
Here, denotes the -th test case.
Each test case is given in the following format:
Output
Print lines in total.
The -th line should contain the answer to the -th test case.
Sample Input 1
7
5 3 10101010
5 3 01010101
5 3 11111111
5 3 00000000
0 0 11111111
0 1 10001111
-1000000000 1000000000 10010011
Sample Output 1
8
5
5
-1
0
-1
1000000000
update @ 2024/3/10 11:27:15