关闭

HDU 2298 Toxophily(三分+二分)

标签: 三分
394人阅读 评论(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(0,0)(X,Y),求其最小能够到达 (X,Y) 的角度(与 X 轴的夹角)

解题思路:

此题为一高中物理题,可以通过分解速度,然后直接求其夹角,当然我们现在为了节约时间,让程序帮我们求夹角,在纸上还得推一下。
V 横纵坐标进行分解:

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

分别在横纵坐标上列两个方程:
{X=VxtY=Vyt12gt2(2)

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

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

代码:

#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;
}
0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:446835次
    • 积分:10671
    • 等级:
    • 排名:第1611名
    • 原创:633篇
    • 转载:5篇
    • 译文:0篇
    • 评论:89条
    博客专栏