HDU ACM 2438 ->Turn the corner 三分求最值

分析:主要参考http://m.blog.csdn.net/blog/yinzm520/22721285这里的解题方法。

关键是要找到小车的运动状态,下面是分析和公式推导;

在小车转弯过程中,黄线是不断地变化的,变化规律是先增大再减小。所以抓住这一点,用三分法。先找一个变量,角度sita(就是上图中用红色标记的那个角),之后就是一系列的推导,算出黄线的长度。角度的范围是(0,pi/2)。

当三分找出最长的黄线长度之后,使之与Y做比较,当它小于Y时,就说明能够通过了

最终可得到:f(angle)=a*sin(angle)+d/cos(angle);又因为a=l-(x-d*sin(angle)/cos(angle)-d*tan(angle)。化简可得:f(angle)=l*sin(angle)-x*tan(angle)+d/cos(angle)。

#include<iostream>
#include<cmath>
using namespace std;

double fx(double l,double x,double d,double angle)
{
	return l*sin(angle)-x*tan(angle)+d/cos(angle);
}

#define PI 3.141592654
#define esp 1e-8

int main()
{
	double x,y,l,w;
	double low,up,mid1,mid2,midv1,midv2;

	ios::sync_with_stdio(false);
	while(cin>>x>>y>>l>>w)
	{
		low=0;
		up=PI/2;    //区间[0,PI/2]相当于旋转了90度
		while(up-low>=esp)  //三分找出最大值
		{
			mid1=low+(up-low)/3;
			mid2=up-(up-low)/3;
			midv1=fx(l,x,w,mid1);
			midv2=fx(l,x,w,mid2);

			if(midv1<midv2)
				low=mid1;
			else
				up=mid2;
		}
		if(y-midv1>esp)
			cout<<"yes"<<endl;
		else
			cout<<"no"<<endl;
	}
    return 0;
}
时间: 2024-08-26 16:42:18

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

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

HDU ACM 1007 Quoit Design 分治法求最近点对

题意:给n个点的坐标,求距离最近的一对点之间距离的一半. 分析:分治法求最近点对. #include<iostream> #include<algorithm> #include<cmath> using namespace std; #define N 100005 double min(double a,double b) { return a<b?a:b; } struct POINT { double x,y; }; POINT point[N],*px[

HDU 4355——Party All the Time——————【三分求最小和】

Party All the Time Time Limit: 6000/2000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 4282    Accepted Submission(s): 1355 Problem Description In the Dark forest, there is a Fairy kingdom where all the spirits wil

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