zoukankan      html  css  js  c++  java
  • Turn the corner


    Problem Description
    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?
    Turn <wbr>the <wbr>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
    题意:西先生开始出去,遇到一个弯,让你求能不能拐过去;
    解题思路:假设过弯时l与底边夹角为s,用三分求最理想过弯角度(用过弯过程中与转弯之后的宽度y相比较),找到最合适的角度,如果最合适的角度,转弯的宽度还是比y大就肯定转不过去,反之就能转过去;
    感悟:寻找过弯条件是最难的,找到之后就简单多了,记录第二道三分题;
    代码(G++ 0ms):
    #include
    #include
    #include
    #define pi 3.141592653589793238
    using namespace std;

    double x,y,l,d;
    double cal(double s)//进行三分的条件
    {
        return l*cos(s)+(d-x*cos(s))/(sin(s));
        //l*cos(s)+(d-x*cos(s))/(sin(s))就是过弯过程中在y方向上的宽
    }

    int main()
    {
        //freopen("in.txt", "r", stdin);
        double left,right,mid,midmid;
        while(scanf("%lf%lf%lf%lf",&x,&y,&l,&d)!=EOF)
        {
            //printf("x=%.1f y=%.1f l=%.1f d=%.1f ",x,y,l,d);
            if(d>x||d>y)
            {
                printf("no ");
                continue;
            }
            left=0;
            right=pi/2;//最大只能是pi/2,不可能倒着转弯吧
            //printf("left=%.1f right=%.1f ",left,right);
            while (right-left>1e-10)
            {
                mid=(left+right)/2;
                midmid=(mid+right)/2;
                //printf("mid=%.4f mid mid=%.4f ",mid,midmid);
                if (cal(mid)>=cal(midmid))//过弯过程中在y方向上的宽,与y比较
                    right=midmid;
                else left=mid;
            }
            //printf("right=%.1f ",right);
            if(cal(right)>y)//如果最大角度过弯时还是比y宽就肯定过不去
                printf("no ");
            else
                printf("yes ");
        }
        return 0;
    }
  • 相关阅读:
    一、Dapper基本操作
    Javascript基础--函数(Function对象)
    【Selenium专题】FAQ_浏览器_ChromeDriver版本导致报错
    mvn install 报错Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.3.2 错误: 找不到符号
    Eclipse中mvn install 报错error in opening zip file
    Maven项目编译时报错缺少tools.jar
    maven-compiler-plugin 版本错误解决方法
    【QTP专题-优化】VBS脚本启动QTP并运行测试
    QTP 场景恢复– 函数调用
    达梦数据库(DaMeng)如何删除IDENTITY自增属性字段
  • 原文地址:https://www.cnblogs.com/wuwangchuxin0924/p/5781631.html
Copyright © 2011-2022 走看看