洛谷P1258 小车问题 数学 推公式

s 表示 AB两地的距离 a 人的速度 b 车的速度
x 表示 车送第一个人送了多远


我们强制方案是这样
车先送第一个人到达距离起点 x 的地方
然后车回去接第二个人 接着车直接送第二个人到终点,这是两人同时到终点


解:设车带第一个人行x,那么折返与另一人相遇,另一人和车的总距离是2x,总速度是a+b,时间就是2x/(a+b),

人走的距离就是2ax/(a+b),应与第一个人被车扔下后走的距离s-x相等

s-x=2ax/a+b

2ax=as+bs-ax-bx

所以(3a+b)x=(a+b)s

 

 1 #include <cstdio>
 2 #include <cstring>
 3 #include <cmath>
 4 #include <cstdlib> 
 5 #include <string>
 6 #include <algorithm>
 7 #include <iomanip>
 8 #include <iostream>
 9 using namespace std ;
10 
11 double a,b,s,t,x ; 
12 
13 int main() 
14 {
15     scanf("%lf%lf%lf",&s,&a,&b) ; 
16     x = ( a+b ) * s /( 3*a+b ) ; 
17     t = x / b + ( s-x ) / a ;
18     printf("%.6lf\n",t) ;
19     return 0 ; 
20 }

 

posted @ 2017-05-29 21:07  third2333  阅读(357)  评论(0编辑  收藏  举报