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

    Turn the corner

    Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
    Total Submission(s): 654 Accepted Submission(s): 291
     
    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?
     
    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
     
     
    Source
    2008 Asia Harbin Regional Contest Online
     
    Recommend
    gaojie
    /*
    x和y值和题目相反,搞了了好几遍
    */
    #include<bits/stdc++.h>
    #define exp 1e-9
    #define pi acos(-1)
    using namespace std;
    /*
    小车不靠墙壁段的直线方程 
    */
    double dis(double Q,double l,double d,double x)
    {
        double b=d/cos(Q)+l*sin(Q);
        return (b-x)/tan(Q);
    }
    int main()
    {
        //freopen("C:\Users\acer\Desktop\in.txt","r",stdin);
        double x,y,l,d;
        while(scanf("%lf%lf%lf%lf",&x,&y,&l,&d)!=EOF)
        {
            double left=0,right=pi/2,mid,midmid;
            //cout<<right<<endl;
            while(right-left>exp)
            {
                mid=left+(right-left)/3;
                midmid=right-(right-left)/3;
                //假设求解最大极值.
                if(dis(mid,l,d,x)>=dis(midmid,l,d,x))
                    right=midmid;
                else 
                    left=mid;
            }
            //cout<<"mid="<<mid<<endl;
            //cout<<(int)dis(mid,l,d,x)<<endl;
            if(dis(mid,l,d,x)<y)
                puts("yes");
            else
                puts("no");
        }
        return 0;
    }
  • 相关阅读:
    C++函数四( 具有默认参数值的函数)
    C++函数三(内联函数和函数重载)
    C++函数二(函数的嵌套调用和递归调用)
    C++关于函数声明定义的位置
    C++函数一(标准库函数,自定义函数)
    C++扑克牌发牌游戏程序(包括C++随机数的解释)
    C++数组二(字符数组)
    C++数组一
    C++程序流程结构
    C++运算符与表达式
  • 原文地址:https://www.cnblogs.com/wuwangchuxin0924/p/5996442.html
Copyright © 2011-2022 走看看