2016SDAU编程练习二1004

来源:互联网 发布:网络棋牌游戏平台源码 编辑:程序博客网 时间:2024/05/22 16:51
Toxophily 


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.<br>We all like toxophily.<br><br>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?<br><br>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. <br>
 


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.<br>Technical Specification<br><br>1. T ≤ 100.<br>2. 0 ≤ x, y, v ≤ 10000. <br>
 


Output
For each test case, output the smallest answer rounded to six fractional digits on a separated line.<br>Output "-1", if there's no possible answer.<br><br>Please use radian as unit. <br>
 


Sample Input
3<br>0.222018 23.901887 121.909183<br>39.096669 110.210922 20.270030<br>138.355025 2028.716904 25.079551<br> 


Sample Output
1.561582<br>-1<br>-1<br> 


Source

The 4th Baidu Cup final


题意:已知发射点坐标为(0,0)和重力加速度g=9.8,给出目标的坐标和初速度,求能够击中目标的最小仰角

思路:就是物理问题套公式,再用二分

感想:二分法主要在精度啊

AC代码:

#include <cstdio>
#include <string>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
double PI = 3.1415926535897932384626433832795;
int T;
double x,y,v,ans;
void Search() {
    double mid,l,r,vx,vy,t,ang;
    l = 0;r = PI/2.0;
    bool d = false; 
    while(r-l>=0.000000001)
    {
        mid = (l+r)/2.0;
        vx = v*cos(mid),vy = v*sin(mid);t = x/vx;
        ang = vy*t-0.5*9.8*t*t;
        if(ang < y)
        {
            l = mid;
        }
        else if(ang > y || vy/9.8 < t)
        {
            d = true;
            ans = mid;
            r = mid;
        }
        else
        {
            d = true;
            ans = mid;
            break;
        }
    }
    if(d) printf("%.6lf\n",ans);
    else printf("-1\n");
}
int main () 
{
    for(scanf("%d",&T);T--;)
    {
        scanf("%lf %lf %lf",&x,&y,&v);
        Search();
    }
    return 0;
}

 
0 0