提交时间:2023-11-12 10:03:57

运行 ID: 110042

#include<bits/stdc++.h> using namespace std; int main() { float s, a, b, c, c0, c1, t1, t2, t3, t4; cin>>s>>a>>b; c0 = 0; c1 = s; do { c = (c0 + c1) / 2; t3 = c / b; //甲乘车到C的时间 t1 = t3 + (s - c) / a; //甲用的总时间 t4 = (c - t3 * a) / (a + b); //小车从C回头与乙相遇的时间 t2 = t4 + t3 + (s - (t3 + t4)*a) / b;//乙用的总时间 if (t1 > t2) c0 = c; else c1 = c; } while (fabs(t1 - t2) > 1e-4); printf("%4.2f", t1); return 0; }