CF1304A.Two Rabbits
入门
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Being tired of participating in too many Codeforces rounds, Gildong decided to take some rest in a park. He sat down on a bench, and soon he found two rabbits hopping around. One of the rabbits was taller than the other.
He noticed that the two rabbits were hopping towards each other. The positions of the two rabbits can be represented as integer coordinates on a horizontal line. The taller rabbit is currently on position x, and the shorter rabbit is currently on position y (x<y). Every second, each rabbit hops to another position. The taller rabbit hops to the positive direction by a, and the shorter rabbit hops to the negative direction by b.

For example, let's say x=0, y=10, a=2, and b=3. At the 1-st second, each rabbit will be at position 2 and 7. At the 2-nd second, both rabbits will be at position 4.
Gildong is now wondering: Will the two rabbits be at the same position at the same moment? If so, how long will it take? Let's find a moment in time (in seconds) after which the rabbits will be at the same point.
厌倦了参加过多的 Codeforces 比赛,Gildong 决定去公园休息。他坐在一张长椅上,很快便发现有两只兔子在周围跳跃。其中一只兔子比另一只更高。
他注意到这两只兔子正朝着彼此跳跃。两只兔子的位置可表示为一条水平直线上的整数坐标。较高的兔子当前位于位置 x,较矮的兔子当前位于位置 y(x<y)。每秒,每只兔子都会跳向另一个位置:较高的兔子向正方向跳跃 a 单位,较矮的兔子向负方向跳跃 b 单位。

例如,设 x=0,y=10,a=2,b=3。在第 1 秒,两只兔子将分别位于位置 2 和 7;在第 2 秒,两只兔子将同时位于位置 4。
Gildong 现在想知道:这两只兔子是否会在同一时刻到达同一位置?如果会,需要多长时间?请找出一个时间点(以秒为单位),使得此时两只兔子处于同一位置。
输入格式
Each test contains one or more test cases. The first line contains the number of test cases t (1≤t≤1000).
Each test case contains exactly one line. The line consists of four integers x, y, a, b (0≤x<y≤109, 1≤a,b≤109) — the current position of the taller rabbit, the current position of the shorter rabbit, the hopping distance of the taller rabbit, and the hopping distance of the shorter rabbit, respectively.
每个测试包含一个或多个测试用例。第一行包含测试用例的数量 t(1≤t≤1000)。
每个测试用例恰好包含一行。该行包含四个整数 x、y、a、b(0≤x<y≤109,1≤a,b≤109),分别表示较高兔子的当前位置、较矮兔子的当前位置、较高兔子的跳跃距离以及较矮兔子的跳跃距离。
输出格式
For each test case, print the single integer: number of seconds the two rabbits will take to be at the same position.
If the two rabbits will never be at the same position simultaneously, print −1.
对于每个测试用例,输出一个整数:两只兔子到达同一位置所需的秒数。
如果两只兔子永远不会同时到达同一位置,则输出 −1。
输入输出样例
输入#1
5 0 10 2 3 0 10 3 3 900000000 1000000000 1 9999999 1 2 1 1 1 3 1 1
输出#1
2 -1 10 -1 1
说明/提示
The first case is explained in the description.
In the second case, each rabbit will be at position 3 and 7 respectively at the 1-st second. But in the 2-nd second they will be at 6 and 4 respectively, and we can see that they will never be at the same position since the distance between the two rabbits will only increase afterward.
第一种情况已在题目描述中说明。
在第二种情况下,两只兔子在第 1 秒时将分别位于位置 3 和 7;但在第 2 秒时,它们将分别位于位置 6 和 4,此后两者之间的距离将持续增大,因此它们永远不会处于同一位置。
输入解题思路,AI测评打分。不知道怎么写?