ACM第二次练习—1004

题意:已知发射点坐标为(0,0)和重力加速度g=9.8,输入目标的坐标(x,y)和初速度v,求能够击中目标的最小仰角,如果可以输出角度,不能输出-1。

思路:直接假设能够击中目标,编写函数列出公式,化成一元二次方程,把公式内的三角函数全部化成tan,然后二分求角度就可以了。

感想:第一次遇到跟物理题联系的,表示物理没学好啊~

代码:



#include<stack>

#include<queue>

#include<cmath>

#include<cstdio>

#include<cstring>

#include<iostream>

#include<algorithm>

#define mset0(t) memset(t,0,sizeof(t))

#define lson a,b,l,mid,cur<<1

#define rson a,b,mid+1,r,cur<<1|1

using namespace std;

const double PI=3.141592653;

const double eps=1e-8;

const int MAXN=500020;

const double g=9.8;

double x,y,v,ans;

int main()

{

if(x==0&&y==0)

printf("0.000000\n"); 

else if(y==0)

printf("-1\n"); 

else 

if(v*v*0.5/g>=y)

printf("%.6lf\n",PI/2); 

else 

printf("-1\n");

continue; }

ans=3; 

double a=g*x*x;

double b=-2*v*v*x; 

double c=2*v*v*y+g*x*x; 

double der=b*b-4*a*c;

if(der<0)

{  

printf("-1\n");

continue;

}  

double ans1=atan((-b-sqrt(der))/(2*a));

double ans2=atan((-b+sqrt(der))/(2*a));

if(ans1>=0&&ans1<=PI/2)

ans=min(ans,ans1);

if(ans2>=0&&ans2<=PI/2)

ans=min(ans,ans2); 

printf("%.6lf\n",ans);

}  

return 0;

}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值