HDU5144 NPY and shot && BestCoder Round #22 1003
2014-12-22 18:24
309 查看
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5144
解题思路:BestCoder官方题解:
最初我采用的是直接暴力的方法,将cosθ的值从0.01到1一直遍历一遍,但是wa了,然后当时就没做出来。直到比赛结束,我很好奇的翻看那些大牛的代码,才知道,这题原来一步就可以求解,可能是当年的物理基础不扎实,才导致现在的自己吧。
一、公式推导:
AC代码:
二、三分
按bestcoder官方题解AC。
AC代码:
解题思路: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; else r=rr; } printf("%.2lf\n",fun(l)); } return 0; }
相关文章推荐
- HDU5144 NPY and shot
- [HDU5144]NPY and shot 解题报告
- HDU 5144 NPY and shot(三分法)
- HDOJ 5144 NPY and shot 简单物理
- 【CUGBACM15级BC第22场 C】hdu 5144 NPY and shot
- NPY and shot (三分求峰值)
- HDOJ 5144 NPY and shot
- NPY and shot(三分)
- hdu 5144 NPY and shot(三分)
- HDU 5144 NPY and shot 三分(物理)
- hdu 5144 NPY and shot(物理+三分法)
- HDOJ 5144 NPY and shot(三分)
- hdu 5144 NPY and shot
- HDU 5144 NPY and shot(三分角度)
- hdu 5144 NPY and shot 物理+三分
- HDU5142 NPY and FFT && BestCoder Round #22 1001
- HDU 5144 NPY and shot (公式+三分)
- BestCoder Round #22 03 NPY and shot(三分)
- HDU 5144 NPY and shot(物理运动学+三分查找)
- hdu 5145 NPY and girls && 莫队算法 && 逆元处理