Codeforces Round #620 (Div. 2) Two Rabbits

解题报告:

思路:x+at = y - bt,解出t,为整数可以相遇。

代码:

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
void solve(){
    ll x, y, a, b;
    scanf("%lld%lld%lld%lld", &x, &y, &a, &b);
    if((y-x) % (a+b))printf("-1\n");
    else printf("%lld\n", (y-x)/(a+b));
}
int main(){
    ll t;
    scanf("%lld", &t);
    while(t--){
        solve();
    }
    return 0;
}
发布了206 篇原创文章 · 获赞 9 · 访问量 1万+

猜你喜欢

转载自blog.csdn.net/jun_____/article/details/104423973
今日推荐