[hdu 2298] 物理推导+二分答案

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2298

 

 

#include<bits/stdc++.h>
using namespace std;

const double pi=acos(-1.0);
const double g=9.8;
const double eps=1e-9;

int main()
{
    int t;
    scanf("%d",&t);
    while (t--)
    {
        double x,y,v;
        scanf("%lf%lf%lf",&x,&y,&v);
        double tant=v*v/g/x;
        double theta=atan(tant);
        double sint=sin(theta);
        double cost=cos(theta);
        double ymax=x*tant-g*x*x/2.0/v/v/cost/cost;
        if (ymax<y) printf("-1\n");
        else
        {
            double l=0,r=theta;
            while (r-l>eps)
            {
                double mid=(l+r)/2.0;
                double tanm=tan(mid);
                double cosm=cos(mid);
                double ym=x*tanm-g*x*x/2.0/v/v/cosm/cosm;
                if (ym>=y) r=mid;
                else l=mid;
            }
            printf("%.6f\n",l);
        }
    }
    return 0;
}

 

posted @ 2017-07-17 11:40  ACMsong  阅读(209)  评论(0编辑  收藏  举报