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
思路:
用下https://blog.csdn.net/u013761036/article/details/24588987博主的圖
意思當車的右側按不同的角度angle靠着右側的牆走的時候,看是否能碰着拐角。即此時車身左側的直線當y=X時,此時的橫座標在-Y的左邊還是右邊,如果滿足情況下,-x<Y,證明車子可以過去,否則則不能。
因爲隨着angle角的增大,-x的值是一個形似開頭向下的拋物線,故可以利用三分來求此拋物線的極點的值
#include<cstdio>
#include<algorithm>
#include<cmath>
using namespace std;
const double wc=1e-6;
const double pi=acos(-1);
double X,Y,l,w;
double f(double x)//傳弧度,返回Y=X時的-x的值
{
return (l*sin(x)+w/cos(x)-X)/tan(x);
}
int main()
{
while(~scanf("%lf%lf%lf%lf",&X,&Y,&l,&w))
{
double ll=0,rr=pi/2.0;
while(rr-ll>wc)
{
double M1=ll+(rr-ll)/3;
double M2=rr-(rr-ll)/3;
if(f(M1)<f(M2))
ll=M1;
else
rr=M2;
}
if(f(ll)<Y)
printf("yes\n");
else
printf("no\n");
}
return 0;
}