HDU 2298 Toxophily
2015-07-20 00:34
393 查看
题意:人的坐标在原点,给出目标坐标(x,y) 和 原点的速度v,0 ≤ x, y, v ≤ 10000.问v和x的角度应该是多少,才能使得从思路原点发射的弓箭射中目标点。
思路:单峰的,可以三分,然而二元一次方程高中都学过,为什么不直接解出答案呢。
v* cosa* t = x; ==》t = x / v /cosa;
v* sina* t- 1/2* g * t * t = y;
消去t;x* tana - 1/2 * g x^2 (1 / v^2 / cosa^2) = y;
利用 sina^2 + cosa^2 = 1;把上面的式子变成
2* v^2 * tana - g * x^2 (1 + tana^2) = 2 v^2 *y;
这就变成了以tana为变量的二元一次方程。公式求一求就OK。
思路:单峰的,可以三分,然而二元一次方程高中都学过,为什么不直接解出答案呢。
v* cosa* t = x; ==》t = x / v /cosa;
v* sina* t- 1/2* g * t * t = y;
消去t;x* tana - 1/2 * g x^2 (1 / v^2 / cosa^2) = y;
利用 sina^2 + cosa^2 = 1;把上面的式子变成
2* v^2 * tana - g * x^2 (1 + tana^2) = 2 v^2 *y;
这就变成了以tana为变量的二元一次方程。公式求一求就OK。
#include <iostream> #include <cstring> #include <cstdio> #include <cmath> #include <algorithm> using namespace std; const double g = 9.8; int main() { int t; scanf("%d",&t); while(t--) { double x,y,v; scanf("%lf%lf%lf",&x,&y,&v); double a = g * x * x; double b = -2 * x * v * v; double c = g * x * x + 2 * v * v * y; double ok = b * b - 4 * a * c; if(ok < 0) { printf("-1\n"); continue; } double x1 = atan((-b + sqrt(ok)) / (2 * a)); double x2 = atan((-b - sqrt(ok)) / (2 * a)); double ans = min(x1,x2); if(ans < 0) printf("-1\n"); else printf("%6f\n",ans); } return 0; }
相关文章推荐
- 用fail2ban阻止SSH和VSFTP暴力破解密码
- 2015BJOI day1第三题 糖果candy
- 4495: Least Prime factor 找到最小质因子P的第N小正整数
- POJ 2965.The Pilots Brothers' refrigerator
- POJ 1753.Flip Game
- POJ 3295.Tautology
- Birthday Cake——直线分割
- Spiral——找规律暴力
- POJ 1166&IOI 1994 The blocks 暴力枚举 解题报告
- hdu 1248
- LCM Challenge(暴力)
- 小晴天老师系列——竖式乘法(暴力)
- URAL 1786 Sandro's Biography
- URAL 1788 On the Benefits of Umbrellas
- URAL 1792 Hamming Code
- URAL 1794 Masterpieces of World Architecture
- URAL 1796 Amusement Park
- HDU 5207 Greatest Greatest Common Divisor
- HDU3183 A 4000 Magic Lamp
- HDU 3123 GCC