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

1004 Toxophily

2016-04-13 21:37 357 查看
题意:

给一个速度V,求最小角度使射出的箭能够到达给定的点(x,y)如果不能输出-1赎罪最小的角度

思路:

根据给出的坐标可以求出关于角度tanx的公式:x^2*g/(2*v^2)*tan^2(ß) - x*tan(ß) +y + x^2*g/(2*v^2) = 0;

可以求出a,b,c 进而求出方程的解

如果x和y同时为0 角度为0;

如果点位与y轴上 角度为90;

方程无解或者解围负数时 输出-1

#include <iostream>
#include <stdio.h>
#include <math.h>
#include <fstream>
#include<iomanip>
using namespace std;
int main()
{
int t;
double a,b,c,angle,z;
double x,y,v,g = 9.8,T,ans1,ans2;
fstream cin("E:/C++/IN/aaa.txt");
cin>>t;
while(t--)
{
cin>>x>>y>>v;
if(x==0&&y==0)
cout<<0<<endl;
else if(x==0&&y>0)
cout<<90<<endl;
else
{
a = g*pow(x,2)/(2*pow(v,2));
b = -x;
c = y+a;
T = pow(b,2) - 4*a*c;
angle = 0;
if(T<0)
printf("-1\n");
else
{
ans1 = ((-b)+pow(T,1.0/2))/(2*a);
ans2 = ((-b)-pow(T,1.0/2))/(2*a);
if(ans1>=0) angle = atan(ans1);
if(ans2>=0)
{
z =  atan(ans2);
if(z<angle) angle = z;
cout << setprecision(6) << setiosflags(ios::fixed) << angle << endl;;
}
if(ans1<0&&ans2<0)
cout<<-1<<endl;
}
}
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: