A13182 | Two Rabbits
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
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 \lt 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.
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 \lt 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.
输入格式
Each test contains one or more test cases. The first line contains the number of test cases $t$ ( $1 \le t \le 1000$ ).
Each test case contains exactly one line. The line consists of four integers $x$ , $y$ , $a$ , $b$ ( $0 \le x \lt y \le 10^9$ , $1 \le a,b \le 10^9$ ) — 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.
Each test case contains exactly one line. The line consists of four integers $x$ , $y$ , $a$ , $b$ ( $0 \le x \lt y \le 10^9$ , $1 \le a,b \le 10^9$ ) — 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.
输出格式
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$ .
If the two rabbits will never be at the same position simultaneously, print $-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.
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.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted