题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2438
网上大牛思路:
可以根据边界,汽车已经转弯,设水平方向为x轴,垂直方向为y轴。
则汽车的内边界(靠近里面的边界)的直线方程式f(x)为:y=x*tan(a)+l*sin(a)+d/cos(a).其中a是汽车与x轴的夹角
当y=X时,求解出的-x即为汽车的内边界到y轴的距离h,若h小于Y即可转弯,若大于Y就不能转弯。
所以只需要利用方程式,求-x的最大值,即可判断能否通过。
由于f(x)是凸函数(随着x的增大y先增大后减小),所以,需要借助三分求解。
图示:
第一道三分求极值题啊!!!
1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include<cmath> 5 using namespace std; 6 #define MIN 1e-7 7 #define PI acos(-1.0) 8 double x,y,l,d; 9 10 double Solve(double tmp){ 11 return (-x+l*sin(tmp)+d/cos(tmp))/tan(tmp); 12 } 13 14 int main(){ 15 while(~scanf("%lf%lf%lf%lf",&x,&y,&l,&d)){ 16 double low=0,high=PI/2.0,mid,mmid; 17 if(x<d||y<d){ puts("no");continue; } 18 while( high-low>MIN ){ 19 mid=(low+high)/2.0; 20 mmid=(mid+high)/2.0; 21 if(Solve(mid)>Solve(mmid))high=mmid+1e-9; 22 else low=mid-1e-9; 23 } 24 if(Solve(mid)<y){ 25 puts("yes"); 26 }else 27 puts("no"); 28 } 29 return 0; 30 } 31 32 33 34