首页 > 代码库 > HDOJ 5144 NPY and shot 简单物理
HDOJ 5144 NPY and shot 简单物理
三分角度....
NPY and shot
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 236 Accepted Submission(s): 87
Problem Description
NPY is going to have a PE test.One of the test subjects is throwing the shot.The height of NPY is H meters.He can throw the shot at the speed of v0 m/s and at the height of exactly H meters.He wonders if he throws the shot at the best angle,how far can he throw ?(The acceleration of gravity, g, is $9.8m/s^2$)
Input
The first line contains a integer $T(T \leq 10000)$,which indicates the number of test cases.
The next T lines,each contains 2 integers $H(0 \leq h \leq 10000m)$,which means the height of NPY,and $v_0(0 \leq v_0 \leq 10000m/s)$, which means the initial velocity.
The next T lines,each contains 2 integers $H(0 \leq h \leq 10000m)$,which means the height of NPY,and $v_0(0 \leq v_0 \leq 10000m/s)$, which means the initial velocity.
Output
For each query,print a real number X that was rounded to 2 digits after decimal point in a separate line.X indicates the farthest distance he can throw.
Sample Input
2 0 1 1 2
Sample Output
0.10 0.99HintIf the height of NPY is 0,and he throws the shot at the 45° angle, he can throw farthest.
Source
BestCoder Round #22
/* *********************************************** Author :CKboss Created Time :2014年12月13日 星期六 23时27分32秒 File Name :C.cpp ************************************************ */ #include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include <string> #include <cstdlib> #include <vector> #include <queue> #include <set> #include <map> #include <cmath> using namespace std; const double eps=1e-6; const double g=9.8; double H,V; double Distan(double degree) { double vx=V*sin(degree); double vy=V*cos(degree); double time = ( vx+sqrt(vx*vx+2*g*H) ) / g; return time*vy; } int main() { //freopen("in.txt","r",stdin); //freopen("out.txt","w",stdout); int T_T; scanf("%d",&T_T); while(T_T--) { scanf("%lf%lf",&H,&V); double low=0.,high=90.; double mid1,mid2,ans=0; while(fabs(high-low)>=eps) { mid1=(low*2+high)/3.; mid2=(low+high*2)/3.; double len1=Distan(mid1); double len2=Distan(mid2); ans=max(ans,max(len1,len2)); if(len2+eps>len1) low=mid1; else high=mid2; } printf("%.2lf\n",ans); } return 0; }
HDOJ 5144 NPY and shot 简单物理
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。