Codeforces Round #620 (Div. 2) A. Two Rabbits
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 xx , and the shorter rabbit is currently on position yy (x<yx<y ). Every second, each rabbit hops to another position. The taller rabbit hops to the positive direction by aa , and the shorter rabbit hops to the negative direction by bb .
For example, let's say x=0x=0 , y=10y=10 , a=2a=2 , and b=3b=3 . At the 11 -st second, each rabbit will be at position 22 and 77 . At the 22 -nd second, both rabbits will be at position 44 .
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.
Input
Each test contains one or more test cases. The first line contains the number of test cases tt (1≤t≤10001≤t≤1000 ).
Each test case contains exactly one line. The line consists of four integers xx , yy , aa , bb (0≤x<y≤1090≤x<y≤109 , 1≤a,b≤1091≤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.
Output
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 .
Example
5
0 10 2 3
0 10 3 3
900000000 1000000000 1 9999999
1 2 1 1
1 3 1 1
2
-1
10
-1
1 小学生水题,就是路程问题,不能整除的话输出-1。
#include <bits/stdc++.h>
using namespace std;
int main()
{
int t;
cin>>t;
while(t--)
{
long long a,b,x,y;
cin>>x>>y>>a>>b;
long long ans=;
if((y-x)%(a+b)==)
{
ans=(y-x)/(a+b);
}
else ans=-;
cout<<ans<<endl;
}
return ;
}
Codeforces Round #620 (Div. 2) A. Two Rabbits的更多相关文章
- Codeforces Round #620 (Div. 2)
Codeforces Round #620 (Div. 2) A. Two Rabbits 题意 两只兔子相向而跳,一只一次跳距离a,另一只一次跳距离b,每次同时跳,问是否可能到同一位置 题解 每次跳 ...
- Codeforces Round #620 (Div. 2) A-F代码 (暂无记录题解)
A. Two Rabbits (手速题) #include<bits/stdc++.h> using namespace std; typedef long long ll; int ma ...
- Codeforces Round #620 (Div. 2) 题解
A. Two Rabbits 思路: 很明显,如果(y-x)%(a+b)==0的话ans=(y-x)/(a+b),否则就为-1 #include<iostream> #include< ...
- Codeforces Round #620 (Div. 2)E LCA
题:https://codeforces.com/contest/1304/problem/E 题意:给定一颗树,边权为1,m次询问,每次询问给定x,y,a,b,k,问能否在原树上添加x到y的边,a到 ...
- Codeforces Round #620 (Div. 2)D dilworld定理
题:https://codeforces.com/contest/1304/problem/D 题意:给定长度为n-1的只含’>'和‘<’的字符串,让你构造出俩个排列,俩个排列相邻的数字之 ...
- Codeforces Round #620 (Div. 2) D
构造一个排列,要求相邻之间的数满足给定的大小关系,然后构造出两个序列,一个序列是所有可能的序列中LIS最长的,一个所有可能的序列中LIS最短的 最短的构造方法:我们考虑所有单调递增的部分,可以发现要让 ...
- Codeforces Round #620 (Div. 2)E(LCA求树上两点最短距离)
LCA求树上两点最短距离,如果a,b之间距离小于等于k并且奇偶性与k相同显然YES:或者可以从a先走到x再走到y再走到b,并且a,x之间距离加b,y之间距离+1小于等于k并且奇偶性与k相同也输出YES ...
- Codeforces Round #620 (Div. 2)D(LIS,构造)
#define HAVE_STRUCT_TIMESPEC #include<bits/stdc++.h> using namespace std; ]; ]; int main(){ io ...
- Codeforces Round #620 (Div. 2) E
LCA的倍增 模板: ], depth[maxn]; int dist[maxn],head[maxn]; void add(int u,int v,int dist0){ a[tot].next=h ...
随机推荐
- Go_CSP并发模型
go语言的最大两个亮点,一个是goroutine,一个就是chan了.二者合体的典型应用CSP,基本就是大家认可的并行开发神器,简化了并行程序的开发难度,我们来看一下CSP. 11.1.CSP是什么 ...
- 解决com.netflix.zuul.FilterProcessor : null异常
ZuulFilter过滤器的filterType方法返回一个字符串代表过滤器的类型,如果return null就会出现以上错误. 在zuul中有以下四种不同生命周期的过滤器类型 pre:路由之前 ro ...
- java1.8特性
java1.8特性 1.lambda表达式 Java8为集合类引入了另一个重要概念:流(stream).一个流通常以一个集合类实例为其数据源,然后在其上定义各种操作 例如 .filter .forEa ...
- oracle-数据库被注入恶意攻击程序的案例恢复
问题描述: Oracle数据库由于重启之后无法正常启动,tab$被清空(ORA-600 16703故障解析—tab$表被清空),导致数据库启动异常 ORA-600 16703报错 一.检测方法: 如下 ...
- 使用pyaudio播放无损音乐(wav)
安装pyaudio sudo apt-get install python-pyaudio python3-pyaudio pip3 install pyaudio 执行第二步可能会遇到如下错误: 根 ...
- Kali国内源更新sources.list
Kali国内源更新sources.list 更新源,个人推荐中科大leafpad /etc/apt/sources.list #中科大 deb http://mirrors.ustc.ed ...
- Docker容器里配置计划任务 crontab(DaoCloud+Docker +Laravel5)
最近项目涉及到一个定时任务的功能,所以去这几天研究了一下 crontab 的使用方法,按照网上的相关教程顺利在自己的电脑上成功开启了这个功能 Laravel + crontab 添加 crontab ...
- WinForm程序打包教程
准备工作 1. 编写完成的WinForm程序 2. 安装部署项 VS2010中有一个自带的安装部署项目,叫:Visual Studio Installer ,通常称为:setup项目,是一个用于自定义 ...
- iOS 音视频播放
播放控制切换为: ijkplayer wiki: https://github.com/changsanjiang/SJVideoPlayer/wiki/Use-ijkplayer 播放控制切换为: ...
- 「CSP-S模拟赛」2019第二场
目录 T1 Jam的计数法 题目 考场思路(正解) T2 「TJOI / HEOI2016」排序 题目 考场思路(假正解) 正解 T3 「THUWC 2017」随机二分图 题目 考场思路 正解 这场考 ...