hdu 2298 - Toxophily [二分]

Toxophily

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

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,让你求出最小的角度使得你射出的箭能够到达给定的点(x,y)。如果不能输出为-1,如果能到达,输出最小的角度。
分析:首先我们建立物理模型,如果射的箭能够达到点(x,y)且到达的角度最小,那么到达这个点的竖直方向上的速度必然是0,或者说是(vy-0)/9.8 < t 时,这个解必定不是最小的,这是首先我们要知道的。然后直接二分角度求解就OK了。
#include <cmath>
#include <cstdio>
#include <string>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
const double PI = 3.1415926535897932384626433832795;
const double eps = 1e-10;
int T;
double x,y,v,ans;
void Search() {
    double mid,l,r,vx,vy,t,mVal;
    l = 0;r = PI/2.0;
    bool suc = false; //判断能不能到达目标点
    //二分查找能够到达该点的角度
    while(r-l>=eps)
    {
        mid = (l+r)/2.0;
        // 求出初始水平速度和初始竖直速度,以及当横坐标到达x时的时间
        vx = v*cos(mid),vy = v*sin(mid);t = x/vx;
        //求出横坐标为x时所能到达的Y值,Y>y则说明角度太大,Y<y说明角度太小
        mVal = vy*t-0.5*9.8*t*t;
        if(mVal < y)
        {
            l = mid;
        }
        else if(mVal > y || vy/9.8 < t)// vy/9.8 < t是用来判断 当前的值是不是最小的【PS:由于OJ数据问题,即便不加也不会WA】
        {
            suc = true;
            ans = mid;
            r = mid;
        }
        else
        {
            suc = true;
            ans = mid;
            break;
        }
    }
    if(suc) printf("%.6lf\n",ans);
    else printf("-1\n");
}
int main () {
    //freopen("input.in","r",stdin);
    for(scanf("%d",&T);T--;)
    {
        scanf("%lf %lf %lf",&x,&y,&v);
        Search();
    }
    return 0;
}
  • 4
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值