1.题目:
Problem Description
在n米长的环形跑道上,甲乙两个人同时同向并排起跑,甲平均速度是每秒a米,乙平均速度是每秒b米,两人起跑后的第一次相遇在起跑线前几米?
Input
输入数据由多个测试实例组成,每个测试实例占一行.
每组数据输入三个量n,a,b.
每组数据输入三个量n,a,b.
Output
输出第一次相遇在起跑线前多少米,每个输出占一行,结果取整。
Sample Input
300 5 4.4
Sample Output
100
Author
2.思路:
这道题目是行程问题。所给例子的答案是:
300÷(5-4.4)=500秒
500×5=2500米
2500÷300=8……100米,这是一道小学奥数的题目。。
3.参考代码:
#include <stdio.h>
int main()
{
double n, a, b, t, x, y, w;
int z;
while (~scanf("%lf%lf%lf", &n, &a, &b)) {
if (a > b)
t = a - b;
else
t = b - a;
y = n / t;
x = a * y;
z = (int)x / n;
w = x - z * n;
printf("%d\n", (int)w);
}
return 0;
}