目录
1.题目
2.中文翻译
3.思路解析:
4.代码实现:
One Person Game
Description
There is an interesting and simple one person game. Suppose there is a number axis under your feet. You are at point A at first and your aim is point B . There are 6 kinds of operations you can perform in one step. That is to go left or right by a,b and c , here c always equals to a+b .
You must arrive B as soon as possible. Please calculate the minimum number of steps.
Input
There are multiple test cases. The first line of input is an integer $T(0 < T ≤ 1000) $indicates the number of test cases. Then T test cases follow. Each test case is represented by a line containing four integers 4 integers A, B, a and b, separated by spaces. ($-2^{31} ≤ A, B < 2^{31}, 0 < a, b < 2^{31}$)
Output
For each test case, output the minimum number of steps. If it’s impossible to reach point B, output “-1” instead.
Examples
intput
2
0 1 1 2
0 1 2 4
output
1
-1
题目描述
有一个有趣而简单的单人游戏。假设你脚下有一个数字轴。你一开始是在点 A ,你的目标是点 B 。一步可以执行6种操作。也就是向左或向右移动 a、b 和 c ,这里 c 总是等于 a+b 。
你必须尽快到达B。请计算最小步数。
输入
有多个测试用例。输入的第一行是一个整数 T(0 输出 对于每个测试用例,输出最小步骤数。如果无法到达B点,则输出“-1”。 样例输入 样例输出 1.题目其实就是求 C1*a + C2*b + C3*c + C4*(-a)+C5*(-b)+C6*(-c)| = |A-B|,根据题意化简之后就变成了 |C1a+C_2b| = |A-B| ,目的就是判断左边这个方程是否有解. 2.欧几里得扩展算法:我的算法专栏里面有讲解。 3.思路解析:
4.代码实现:
#include