您的位置:首页 > 运维架构

HDU 2298 Toxophily(水~)

2016-08-02 18:54 288 查看
Description

从(0,0)点射箭,速度为v,重力加速度g=9.8,想射到(x,y)处的一个苹果,求最小出射角度

Input

第一行为一整数T表示用例组数,每组用例为三个浮点数x,y,v表示苹果位置和箭的出射速度(T<=100,1<=x,y,v<=10000)

Output

对于每组用例,如果可以射到苹果则输出最小出射角度,否则输出-1

Sample Input

3

0.222018 23.901887 121.909183

39.096669 110.210922 20.270030

138.355025 2028.716904 25.079551

Sample Output

1.561582

-1

-1

Solution



判断一下x1,x2是否在[0,pi]之间然后选一个合法的较小值即可

Code

#include<cstdio>
#include<iostream>
#include<cmath>
using namespace std;
#define g 9.8
#define pi acos(-1.0)/2.0
int main()
{
int T;
double x,y,v;
scanf("%d",&T);
while(T--)
{
scanf("%lf%lf%lf",&x,&y,&v);
double a=g*x*x;
double b=-2.0*x*v*v;
double c=2.0*y*v*v+g*x*x;
double d=b*b-4.0*a*c;
if(d<0)
{
printf("-1\n");
continue;
}
d=sqrt(d);
double x1=atan((-b+d)/(2.0*a)),x2=atan((-b-d)/(2.0*a));
if(x1<0||x1>pi&&x2<0||x2>pi)printf("-1\n");
else if(x1<0||x1>pi)printf("%.6lf\n",x2);
else if(x2<0||x2>pi)printf("%.6lf\n",x1);
else printf("%.6lf\n",x1<x2?x1:x2);
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: