题目链接 : http://acm.tju.edu.cn/toj/showp2996.html
Description
“Superman” Howard in the NBA slam dunk contest asked to increase the height of the rim to perform slam dunk, but has not been approved. Now our hhb also want to perform for us, but this time what he wants to perform is a shot, put the rim the higher, hhb’s performances the more wonderful, so now please help hhb calculate the maximum height of the rim. Ignore the ball and box size.
………….
这道题看起来很简单,实际上编程确实很容易,比较难得是根据物理和数学知识求出计算公式。联立下面三个公式:
- H = h + (v*sinX)*t - 0.5*g*t*t ······ ①
- t = l / (v*cosX) ······ ②
- cosx^2 = 1/(1+tanx^2) ······ ③
解得H = -atanx^2 +ltanx + h - a。其中a = 0.5gl^2/v^2。然后利用二次函数求最值得公式就能求出H的最大值了。
#include <stdio.h>
using namespace std;
int main()
{
float h,l,v,g=9.8;
while(~scanf("%f%f%f",&h,&l,&v) && (h+v+l)){
printf("%.2f\n",h-0.5*g*l*l/(v*v)+0.5*v*v/g);
}
}