码迷,mamicode.com
首页 > 其他好文 > 详细

[hdu2298] 物理推导+二分答案

时间:2017-07-17 12:33:05      阅读:137      评论:0      收藏:0      [点我收藏+]

标签:答案   php   int   auto   acm   ref   href   std   can   

题目链接: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;
}

 

[hdu2298] 物理推导+二分答案

标签:答案   php   int   auto   acm   ref   href   std   can   

原文地址:http://www.cnblogs.com/acmsong/p/7193546.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!