[恢]hdu 2529

2012-01-02 17:22:53

地址:http://acm.hdu.edu.cn/showproblem.php?pid=2529

题意:中文。

mark:设v的水平分量为x,则最终距离和x的关系应该是先增后减,遂三分。。。

代码:

# include <stdio.h>
# include <math.h>


double l, v ;


double f(double x)
{
return sqrt(v*v-x*x)*l/x - 0.5*9.8*l*l/(x*x) ;
}


int main ()
{
double left, right, m1, m2, h ;
while (~scanf ("%lf%lf%lf", &h, &l, &v))
{
if (h == 0 && l == 0 && v == 0) break ;
left = 0, right = v ;
m1 = (left+right) / 3 ;
m2 = (left+right)*2/3 ;
while (right - left > 1e-5)
{
if (f(m1) < f(m2)) left = m1, m1 = m2, m2 = (m1+right)/2 ;
else right = m2, m2 = m1, m1 = (m2+left)/2 ;
}
printf ("%.2lf\n", f(m1)+h) ;
}
return 0 ;
}



posted @ 2012-01-07 00:36  Seraph2012  阅读(151)  评论(0编辑  收藏  举报