CF1304A Two Rabbits

A. Two Rabbits

原题

Problem Restatement

两个兔子以恒定速度相向而行,求相遇时间?若无法在整时间相遇,输出(-1)

Solution

相遇问题,距离除以总速度为时间,看时间是否为整数即可。

Code

#include <bits/stdc++.h>

void solve(){
	int x,y,a,b;
	scanf("%d %d %d %d", &x, &y, &a, &b);
	if((y-x)%(a+b)==0)
		printf("%d
", (y-x)/(a+b));
	else printf("-1
");
}

int main(){
	int T=1;
	scanf("%d", &T);
	while(T--){
		solve();
	}
	return 0;
}
原文地址:https://www.cnblogs.com/leachim/p/12359792.html