hdu 2603

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

题意:从高度为3米距离天花板0.5米处抛掷一物体,倾角为a,质量为m,初速度为v。若碰到天花板则以反射定律反射出去。问物体能抛多远。

mark:推公式解的物理数学题。只要还记得S = vt + 0.5gt^2的自由落体公式,根据其求出总飞行时间,剩下的都很好解决。注意解方程的时候考虑若有2个解,取哪一个。

代码:

 1 # include <stdio.h>
 2 # include <math.h>
 3 
 4 
 5 double pi = acos(-1.0), g = 9.87 ;
 6 
 7 
 8 int main ()
 9 {
10     double v, m, a, vx, t, t1, t2 ;
11     while (~scanf ("%lf%lf%lf", &v, &m, &a))
12     {
13         a = a/180*pi ;
14         vx = v*cos(a), v = v*sin(a) ;
15         if (v <= sqrt(g)) //will not touch the ceiling
16             t = (v+sqrt(v*v+6*g))/g ;
17         else
18         {
19             t1 = 2*(v-sqrt(v*v-g))/g ;
20             t2 = (sqrt(v*v+6*g)-v) / g ;
21             t = t1 + t2 ;
22         }
23         printf ("%.3lf
", vx * t) ;
24     }
25     return 0 ;
26 }
原文地址:https://www.cnblogs.com/lzsz1212/p/3300244.html