hdu 2438 Turn the corner(三分)

Turn the corner

                                                        Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)

Total Submission(s): 2010    Accepted Submission(s): 765

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

题意:

         给出街道在x轴的宽度X,y轴的宽度Y,还有车的长l和宽w,判断是否能够转弯成功。

题解:

        盗网上大牛一张图,画的很详细

      尽可能让车贴着外面的墙璧转弯,也就是图中的x轴和y轴,此时红线的方程就是图中的方程,此时p点的位置就是让y=X时解得的x值,要保证p点在Y内,也就是-x<y,假若在转弯的所有角度中都满足这个条件,那么就能转弯,分析得,-x先增大后减小,所以用三分求最大-x值。

代码:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;
const double pi=acos(-1.0);
const double eps=1e-6;
double x,y,l,w;
double solve(double angle)
{
    return (-x+l*sin(angle)+w/cos(angle))/tan(angle);
}
int main()
{
    while(~scanf("%lf%lf%lf%lf",&x,&y,&l,&w))
    {
        double l=0,r=pi/2,mid1,mid2;
        while(l+eps<r)
        {
            mid1=l+(r-l)/3;
            mid2=r-(r-l)/3;
            if(solve(mid1)>solve(mid2))
            r=mid2;
            else
            l=mid1;
        }
        if(solve(l)<y)
        printf("yes\n");
        else
        printf("no\n");
    }
    return 0;
}

时间: 2024-12-23 22:16:24

hdu 2438 Turn the corner(三分)的相关文章

HDU 2438 Turn the corner(三分枚举角度)

题目大意:给你一个拐角,两边的路的宽度分别为x,y.汽车的长和宽分别为h,w.问你这个汽车否转弯成功. 解题思路:如图,枚举角度. 这是一个凸函数所以三分枚举角度. Turn the corner Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 2009    Accepted Submission(s): 765 Problem De

HDU 2438 Turn the corner (计算几何 + 三分)

Turn the corner Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 2059    Accepted Submission(s): 785 Problem Description Mr. West bought a new car! So he is travelling around the city. One day h

hdu 2483 Turn the corner(三分)

Turn the corner Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 1899    Accepted Submission(s): 719 Problem Description Mr. West bought a new car! So he is travelling around the city. One day h

hdu 2348 Turn the corner(三分&amp;&amp;几何)(中等)

Turn the corner Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 2229    Accepted Submission(s): 856 Problem Description Mr. West bought a new car! So he is travelling around the city. One day h

HDU ACM 2438 -&gt;Turn the corner 三分求最值

分析:主要参考http://m.blog.csdn.net/blog/yinzm520/22721285这里的解题方法. 关键是要找到小车的运动状态,下面是分析和公式推导: 在小车转弯过程中,黄线是不断地变化的,变化规律是先增大再减小.所以抓住这一点,用三分法.先找一个变量,角度sita(就是上图中用红色标记的那个角),之后就是一系列的推导,算出黄线的长度.角度的范围是(0,pi/2). 当三分找出最长的黄线长度之后,使之与Y做比较,当它小于Y时,就说明能够通过了 最终可得到:f(angle)=

Turn the corner (三分)

Turn the corner Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 151 Accepted Submission(s): 61   Problem Description Mr. West bought a new car! So he is travelling around the city. One day he come

codeforces 782B The Meeting Place Cannot Be Changed+hdu 4355+hdu 2438 (三分)

B. The Meeting Place Cannot Be Changed The main road in Bytecity is a straight line from south to north. Conveniently, there are coordinates measured in meters from the southernmost building in north direction. At some points on the road there are n

hdu 2438Turn the corner 三分

Turn the corner Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 2785    Accepted Submission(s): 1102 Problem Description Mr. West bought a new car! So he is travelling around the city. One day h

HDU 4869 Turn the pokers(推理)

HDU 4869 Turn the pokers 题目链接 题意:给定n个翻转扑克方式,每次方式相应能够选择当中xi张进行翻转.一共同拥有m张牌.问最后翻转之后的情况数 思路:对于每一些翻转,假设能确定终于正面向上张数的情况,那么全部的情况就是全部情况的C(m, 张数)之和.那么这个张数进行推理会发现,事实上会有一个上下界,每隔2个位置的数字就是能够的方案,由于在翻牌的时候,相应的肯定会有牌被翻转,而假设向上牌少翻一张,向下牌就要多翻一张.奇偶性是不变的,因此仅仅要每次输入张数,维护上下界,最后