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 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

#include <iostream>
#include<time.h>
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<string>
#include<cmath>
#include<map>

#define eps 1e-10
#define PI acos(-1)

using namespace std;

const int maxn = 220;

#define LL long long

double x, y, l, w;

double Del(double ang)
{
    double s = l*cos(ang)+w*sin(ang)-x;
    double h = s*tan(ang)+w*cos(ang);
    return h;
}

int main()
{
    while(cin >>x>>y>>l>>w)
    {

        double Max = 0.0;
        double left = 0;
        double right = PI/2.0;
        while(right-left > eps)
        {
            double mid = (right+left)/2.0;
            double rmid = (mid+right)/2.0;
            double xp1 = Del(mid);
            double xp2 = Del(rmid);
            if(xp1 > xp2) right = rmid;
            else left = mid;
            Max = max(Max, max(xp1, xp2));
        }
        if(Max > y) cout<<"no"<<endl;
        else cout<<"yes"<<endl;
    }
}
时间: 2024-08-24 13:05:20

HDU 2438 Turn the corner(三分枚举角度)的相关文章

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 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

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 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 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 4454 Stealing a Cake(枚举或三分)

题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=4454 思路:枚举角度,确定圆上点的位置,取最小值. 点到矩形最短距离:若点在矩形边所表示的范围内,则到矩形最短距离为x或y坐标到矩形边的距离.否则为点到矩形顶点的距离. #include<cstdio> #include<cmath> #include<cstring> #include<iostream> #include<algorithm> #

HDU 4454 Stealing a Cake(三分暴力枚举)

题目大意:给你一个点,一个圆,一个矩形让你求出来,点到圆然后再到矩形的距离.圆和矩形你可以认为是可以穿过的. 解题思路:三分枚举点到圆的位置,然后求出来总长度,找到一个最小的长度.枚举点的坐标的时候可以枚举角度,也可以枚举坐标.总长度等于点到圆上的点的距离加上圆上的点到矩形四个线段的最小距离的和. PS:输出%0.2lf所以精度要求不高,自我感觉枚举角度会更保证精度. Stealing a Cake Time Limit: 5000/2000 MS (Java/Others)    Memory