503人阅读 评论(0)

Toxophily

Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 2304    Accepted Submission(s): 1270

Problem Description
The recreation center of WHU ACM Team has indoor billiards, Ping Pang, chess and bridge, toxophily, deluxe ballrooms KTV rooms, fishing, climbing, and so on.
We all like toxophily.

Bob is hooked on toxophily recently. Assume that Bob is at point (0,0) and he wants to shoot the fruits on a nearby tree. He can adjust the angle to fix the trajectory. Unfortunately, he always fails at that. Can you help him?

Now given the object’s coordinates, please calculate the angle between the arrow and x-axis at Bob’s point. Assume that g=9.8N/m.

Input
The input consists of several test cases. The first line of input consists of an integer T, indicating the number of test cases. Each test case is on a separated line, and it consists three floating point numbers: x, y, v. x and y indicate the coordinate of the fruit. v is the arrow’s exit speed.
Technical Specification

1. T ≤ 100.
2. 0 ≤ x, y, v ≤ 10000.

Output
For each test case, output the smallest answer rounded to six fractional digits on a separated line.
Output "-1", if there’s no possible answer.

Please use radian as unit.

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

V$V$ 横纵坐标进行分解：

{Vx=VcosθVy=Vsinθ(1)

{X=VxtY=Vyt12gt2(2)

(1)(2)$(1)、(2)$整理为一个方程得到:
Xtanθ12g(XVx)2Y=0

f(θ)=Xtanθ12g(XVx)2Y$f(\theta)=X*tan\theta -\frac 1 2g*(\frac X {V_x})^2-Y$，经过（不用）证明，f$f$ 函数为凸函数，所以求其极值为小球能够在 Y$Y$ 轴走的最远距离，如果 f(θ)max<Y$f(\theta)_{max}\lt Y$，那么小球一定到达不了 (X,Y)$(X,Y)$ 点，输出 1$-1$，否则，小球能够到达 (X,Y)$(X,Y)$ 点，那么我们求其最小的角度 θ$\theta$，现在只需要求其 [0,θ]$[0,\theta_{极值点}]$，又因为在这一部分为单调递增函数，所以可以二分求得 θ$\theta_{最小值}$

#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1);
const double eps = 1e-8;
double X, Y, V;
double f(double x){
double ans = X*tan(x)-4.9*(X/(V*cos(x)))*(X/(V*cos(x)))-Y;
return ans;
}
double sanfen(double left, double right){
double midl, midr;
while (right-left > eps){
midl = (left + right) / 2;
midr = (midl + right) / 2;
if(f(midl) >= f(midr)) right = midr;
else left = midl;
}
return left;
}
double erfen(double left, double right){
while(right-left > eps){
double mid = (left + right) * 0.5;
if(f(mid) < -eps) left = mid;
else right = mid;
}
return right;
}
int main()
{
int T; scanf("%d", &T);
while(T--){
scanf("%lf%lf%lf",&X,&Y,&V);
double tm = sanfen(0,0.5*PI);
if(f(tm) < -eps) { puts("-1"); continue; }
printf("%.6f\n",erfen(0, tm));
}
return 0;
}


个人资料
等级：
访问量： 54万+
积分： 1万+
排名： 1632
博客专栏
 ITAK的ACM之路 文章：295篇 阅读：352372 ACM_组合数学 文章：27篇 阅读：33614 计算机专业的相关课程知识 文章：24篇 阅读：37194
友情推荐