zoukankan      html  css  js  c++  java
  • Toxophily HDU

    题目:https://vjudge.net/contest/364745#problem/B

    先用三分求出最高点Y,然后在进行二分,求出角度

    注意写法   PI的弧度是  

    acos(-1)/2-EPS接近90度的时候相当于除以0
    二分的精度可以用迭代次数来保证,比如100次
    #include <iostream>
    #include <cmath>
    using namespace std;
    const double EPS = 1e-8;
    int T; double x, y, v;
    double f(double a)//角度为a时对应的高度
    {
        double t = x/(v*cos(a));
        return v*sin(a)*t - 9.8/2*t*t;
    }
    int main()
    {
        cin >> T;
        while(T--)
        {
            cin >> x >> y >> v;
            double L = 0, R = acos(-1)/2-EPS;
            if(x==0) //特判,否则三角函数会智障掉
            {
                if(v*v/2/9.8 > y) printf("%.6lf
    ", R);
                else printf("-1
    ");
                continue;
            }
            for(int i=1;i<=100;i++)
            {
                double mid_L = (L+R) / 2;
                double mid_R = (mid_L+R) / 2;
                if(f(mid_L) > f(mid_R))
                {
                    R = mid_R;
                } else {
                    L = mid_L;
                }
            }
            if(f(L) < y) {printf("-1
    "); continue;}
            R = L, L = 0;
            for(int i=1;i<=100;i++)
            {
                double mid = (L+R)/2;
                if(f(mid) < y)
                {
                    L = mid;
                } else {
                    R = mid;
                }  
            }
            printf("%.6lf
    ", L);
        }
    }
  • 相关阅读:
    OO第三单元作业总结
    OO第二单元作业总结
    OO第一单元总结
    OO第四单元总结
    OO第三单元总结
    OO第二单元总结
    OO第一单元总结
    OO Unit4 总结
    OO Unit3 总结
    OO Unit2 总结
  • 原文地址:https://www.cnblogs.com/SunChuangYu/p/12670631.html
Copyright © 2011-2022 走看看