1004
来源:互联网 发布:怎么增强JS的兼容性 编辑:程序博客网 时间:2024/06/03 07:18
概述:一支箭从原点以速度V发射,发射角任意,对于给定点(x,y),求这只箭能否射中该点,如果能射中,输出射中时的最小仰角,否则,输出-1.
思路:如果射的箭能够达到点(x,y)且到达的角度最小,那么到达这个点的竖直方向上的速度必然是0,将速度分解为Vx和Vy,用x/Vx求出时间t,再用t求出Y,与y来比较,如果Y==y时,输出,求解的过程是一个二分的过程。
感想:看来学好高中物理很重要。
#include <iostream>#include <cstdio>#include <cmath>#include <fstream>using namespace std;const double PI = 3.1415926535897932384626433832795;const double g = 9.8;double search(double x, double y, double v){double mid, l=0, r = PI / 2.0, Vx, Vy, t, Ymax,ans;bool flag = 0;while (r - l >= 1e-10){mid = (l + r) / 2.0;Vx = v*cos(mid); Vy = v*sin(mid); t = x / Vx;Ymax = Vy*t - 0.5*g*t*t;if (Ymax < y)l = mid;else if (Ymax > y || Vy / 9.8 < t){flag = 1;ans = mid; r = mid;}else{flag = 1;ans = mid;break;}}if (flag)return ans;elsereturn -1; }int main(){//ifstream cin("aaa.txt");double X, Y, V;int T;cin >> T;while (T--){cin >> X >> Y >> V;double a = search(X,Y,V);if (a == -1)printf("-1\n");else printf("%.6lf\n", a);}return 0;}
0 0
- [1004]
- 1004
- 1004
- 1004
- 1004
- 1004
- 1004
- 1004
- 1004
- 1004
- 1004
- 1004
- 1004
- 1004
- 1004
- 1004
- 1004
- 1004
- 九度 1007
- UVA 1452Jump 【约瑟夫环】
- Boostrap框架学习总结
- findChessboardCorners函数学习笔记
- 【复习笔记】 cocos2d-x 2.x 渲染特效实现 六 节点树的描边效果
- 1004
- 【脚本化文档】——DOM概览&选取文档元素
- VirtualBox虚拟机网络连接
- 2016年中国虚拟现实行业研究报告
- C语言中取余与取模的区别
- 进程与线程大战几百回合?
- switch体内部优化运行原理
- opencv 模版匹配matchtemplate方法介绍
- css 复习-position定位