1500字范文,内容丰富有趣,写作好帮手!
1500字范文 > HDU5144 NPY and shot BestCoder Round #22 1003

HDU5144 NPY and shot BestCoder Round #22 1003

时间:2021-08-01 08:20:08

相关推荐

HDU5144 NPY and shot  BestCoder Round #22 1003

题目链接:http://acm./showproblem.php?pid=5144

解题思路:BestCoder官方题解:

这是一个高一物理题。扔的距离与投掷角度的函数,符合单峰性质,所以三分角度就行了。当角度为θ时,设横向速度为vx=cos(θ)*v0,纵向速度为vy=sin(θ)*v0,则扔的距离为: (vy/g+sqrt((vy*vy/(g*2)+h)*2/g))*vx;这个应该手算一下,很容易就能推出来的,具体技巧是将速度延x,y轴分解,然后算一下球的滞空时间,然后乘以横向速度就行。

最初我采用的是直接暴力的方法,将cosθ的值从0.01到1一直遍历一遍,但是wa了,然后当时就没做出来。直到比赛结束,我很好奇的翻看那些大牛的代码,才知道,这题原来一步就可以求解,可能是当年的物理基础不扎实,才导致现在的自己吧。

一、公式推导:

AC代码:

#include<iostream>#include<cstdio>#include<cmath>using namespace std;const double g=9.8;int main(){int T;scanf("%d",&T);while(T--){double h,v;scanf("%lf%lf",&h,&v);printf("%.2lf\n",1.0*v*sqrt(1.0*v*v+2*g*h)/g);}return 0;}

二、三分

按bestcoder官方题解AC。

AC代码:

#include<iostream>#include<cstdio>#include<cmath>using namespace std;double h,v;double fun(double a){double g=9.8,vx=v*cos(a),vy=v*sin(a);return vx*(vy/g+sqrt((2*h*g+vy*vy)/(g*g)));}int main(){int T;scanf("%d",&T);while(T--){scanf("%lf%lf",&h,&v);double l=0,r=90.0;while((r-l)>=1e-10){double ll,rr;ll=(l*2+r)/3;rr=(l+2*r)/3;if(fun(ll)<fun(rr))l=ll;elser=rr;}printf("%.2lf\n",fun(l));}return 0;}

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。