zoukankan      html  css  js  c++  java
  • H

    Mr. West bought a new car! So he is travelling around the city. 

    One day he comes to a vertical corner. The street he is currently in has a width x, the street he wants to turn to has a width y. The car has a length l and a width d. 

    Can Mr. West go across the corner? 
     

    Input

    Every line has four real numbers, x, y, l and w. 
    Proceed to the end of file. 

    Output

    If he can go across the corner, print "yes". Print "no" otherwise. 

    Sample Input

    10 6 13.5 4
    10 6 14.5 4

    Sample Output

    yes
    no

    思路:

    用下https://blog.csdn.net/u013761036/article/details/24588987博主的图

    意思当车的右侧按不同的角度angle靠着右侧的墙走的时候,看是否能碰着拐角。即此时车身左侧的直线当y=X时,此时的横坐标在-Y的左边还是右边,如果满足情况下,-x<Y,证明车子可以过去,否则则不能。

    因为随着angle角的增大,-x的值是一个形似开头向下的抛物线,故可以利用三分来求此抛物线的极点的值

    #include<cstdio>
    #include<algorithm>
    #include<cmath>
    using namespace std;
    const double wc=1e-6;
    const double pi=acos(-1);
    double X,Y,l,w;
    double f(double x)//传弧度,返回Y=X时的-x的值
    {
        return (l*sin(x)+w/cos(x)-X)/tan(x);
    }
    int main()
    {
        while(~scanf("%lf%lf%lf%lf",&X,&Y,&l,&w))
        {
            double ll=0,rr=pi/2.0;
            while(rr-ll>wc)
            {
                double M1=ll+(rr-ll)/3;
                double M2=rr-(rr-ll)/3;
                if(f(M1)<f(M2))
                    ll=M1;
                else
                    rr=M2;
            }
            if(f(ll)<Y)
                printf("yes
    ");
            else
                printf("no
    ");
        }
        return 0;
    }
  • 相关阅读:

    入门动态规划问题
    AC自动机
    KMP算法
    [OpenGL]用鼠标拖拽图形移动
    HDU-2222 Keywords Search
    Trie
    Manacher算法
    linux环境搭建
    Android Studio使用JNI和NDK进行开发
  • 原文地址:https://www.cnblogs.com/dchnzlh/p/10427246.html
Copyright © 2011-2022 走看看