NPY and shot (物理题)

作者: qwq 分类: ACM 发布时间: 2017-07-13 15:17

 

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/s29.8m/s2)

InputThe first line contains a integer T(T10000)T(T≤10000),which indicates the number of test cases.
The next T lines,each contains 2 integers H(0h10000m)H(0≤h≤10000m),which means the height of NPY,and v0(0v010000m/s)v0(0≤v0≤10000m/s), which means the initial velocity.OutputFor 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.99

        
  

Hint

If the height of NPY is 0,and he throws the shot at the 45° angle, he can throw farthest.

题很简单,把物理公式推出来就可以了,一遍过

 

#include<iostream>
#include<cmath>
#include<algorithm>
#include<cstdio>
using namespace std;
 int h,v;
 double judge(double a){
 	//v*cosa(vsina+sqrt(v2sin2a+2gh)/g
 	return (v*cos(a))*((v*sin(a)+sqrt(v*v*sin(a)*sin(a)+2*9.8*h))/9.8);
 }
 int main(){

	 int t;
 	scanf("%d",&t);
 	while(t--){
 	scanf("%d%d",&h,&v);
 		double l=0,r=0.5*3.1415926535;
 		double mid1,mid2;
 		while(r-l>1e-8){
 			mid1=(l+r)/2.0;
 			mid2=(mid1+r)/2.0;
 			if(judge(mid1)>judge(mid2)){
 				r=mid2;
			 }else{
			 	l=mid1;
			 }
		 }
 		printf("%.2f\n",judge(r));
	 }
 	
 }

 

发表评论

电子邮件地址不会被公开。 必填项已用*标注