首页 > 其他 > 详细

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

时间:2017-05-29 21:26:24      阅读:397      评论:0      收藏:0      [点我收藏+]

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 }

 

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

原文:http://www.cnblogs.com/third2333/p/6919019.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!