在这个问题中,我们得到两个值S和N,分别表示以Km / h为单位的流速度和上,下流的时间比。我们的任务是从溪流的速度和上下溪流的时间比例中找出人的速度。
让我们举个例子来了解这个问题,
S = 5, N = 2输出结果
15
解决该问题的简单方法是对划船问题使用数学公式。因此,让我们看看该公式将如何工作-
speed of man = x km/h speed of stream = S km/h speed of man downstream i.e. with stream = (x+S) km/h speed of man upstream i.e. against stream = (x-S) km/h Time to travel the distance downstream = T Time to travel the distance upstream = n*T Distance travelled upstream = (x - S)*n*T Distance travelled upstream = (x + S)*T As both the distances are same, (x + S) * T = (x - S)*n*T x + S = nx - nS s + nS = nx - x s*(n + 1) = x(n - 1)
$$x = \ frac {S *(S + 1)} {(S-1)} $$
该程序说明了我们解决方案的工作原理,
#include <iostream> using namespace std; float calcManSpeed(float S, int n) { return ( S * (n + 1) / (n - 1) ); } int main() { float S = 12; int n = 3; cout<<"人的速度是 "<<calcManSpeed(S, n)<<" km/hr"; return 0; }输出结果
人的速度是 24 km/hr