三重变换AI (CI翻译)
Problem Statement
Consider an operation on a triple $(x,y,z)$ of non-negative integers. In the operation, $(x,y,z)$ is replaced according to the following rules:
考虑对非负整数三元组 $(x,y,z)$ 进行一次操作。操作按照以下规则替换 $(x,y,z)$:AI (CI翻译)
- If
$y+z<x$: replace with$(x-y-z,\ 2y,\ 2z)$. - If
$x+z<y$: replace with$(2x,\ y-x-z,\ 2z)$. - If
$x+y<z$: replace with$(2x,\ 2y,\ z-x-y)$. - If none of the above conditions hold: replace with
$(y+z-x,\ x+z-y,\ x+y-z)$.
- 如果
$y+z<x$:替换为$(x-y-z,\ 2y,\ 2z)$。 - 如果
$x+z<y$:替换为$(2x,\ y-x-z,\ 2z)$。 - 如果
$x+y<z$:替换为$(2x,\ 2y,\ z-x-y)$。 - 如果以上条件均不满足:替换为
$(y+z-x,\ x+z-y,\ x+y-z)$。
Note that every triple of non-negative integers falls into exactly one of the above four cases.
注意,每个非负整数三元组恰好满足上述四种情况中的一种。AI (CI翻译)
You are given non-negative integers $A_1, A_2, A_3, B_1, B_2, B_3$. Consider performing the operation on the triple $(A_1,A_2,A_3)$ zero or more times to obtain $(B_1,B_2,B_3)$. Find the minimum number of operations required to do so. If it is impossible to obtain $(B_1,B_2,B_3)$ no matter how many times the operation is performed, output -1.
给定非负整数 $A_1, A_2, A_3, B_1, B_2, B_3$。考虑对三元组 $(A_1,A_2,A_3)$ 进行零次或多次操作,得到 $(B_1,B_2,B_3)$。请找出所需的最少操作次数。如果无论进行多少次操作都无法得到 $(B_1,B_2,B_3)$,输出 -1。AI (CI翻译)
$T$ test cases are given; solve each of them.
给出 $T$ 组测试数据,请分别求解。AI (CI翻译)
Constraints
约束条件
AI (CI翻译)$1\leq T\leq 300$$0\leq A_1, A_2, A_3, B_1, B_2, B_3\leq 10^8$- All input values are integers.
$1\leq T\leq 300$$0\leq A_1, A_2, A_3, B_1, B_2, B_3\leq 10^8$- 所有输入值均为整数。
Input
输入格式
AI (CI翻译)The input is given from Standard Input in the following format:
输入从标准输入按以下格式给出:AI (CI翻译)
T
\mathrm{case}_1
\mathrm{case}_2
\vdots
\mathrm{case}_T
T
\mathrm{case}_1
\mathrm{case}_2
\vdots
\mathrm{case}_TAI (CI翻译)
Each test case is given in the following format:
每组测试数据按以下格式给出:AI (CI翻译)
A_1 A_2 A_3 B_1 B_2 B_3
A_1 A_2 A_3 B_1 B_2 B_3AI (CI翻译)
Output
输出格式
AI (CI翻译)Output one line per test case.
每组测试数据输出一行。AI (CI翻译)
For each test case, output the minimum number of operations required to obtain $(B_1,B_2,B_3)$ by performing the operation on the triple $(A_1,A_2,A_3)$ zero or more times. If it is impossible to obtain $(B_1,B_2,B_3)$ no matter how many times the operation is performed, output -1.
对于每组测试数据,输出从三元组 $(A_1,A_2,A_3)$ 开始,通过进行零次或多次操作得到 $(B_1,B_2,B_3)$ 所需的最少操作次数。如果无论进行多少次操作都无法得到 $(B_1,B_2,B_3)$,输出 -1。
AI (CI翻译)
样例
6
2 3 4 2 3 4
2 3 4 5 3 1
2 3 4 1 6 2
2 3 4 4 3 2
1 0 0 0 0 1
0 0 0 0 0 0
0
1
2
-1
-1
0
题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(gpt-6.1-sol),如有出入请以原文为准。