Turn the cornerTime Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 2300 Accepted Submission(s): 889
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
Sample Output
|
题意:给定两条路的宽度和汽车的长宽判断汽车能否通过这两条路组成的拐角
解题思路:在保证车尾不会撞墙的情况下对角度进行三分求出车头所需要的最大宽度然后和道路判断即可
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#define eps 1e-8
#define PI 3.141592653589793238
using namespace std;
double x,y,l,d;
double getH(double angle){
double s=l*cos(angle)+d*sin(angle)-x;//汽车最右边的一个角和拐角的长度
double h=s*tan(angle)+d*cos(angle);//所占用的长度
return h;
}
int main()
{
while(scanf("%lf%lf%lf%lf",&x,&y,&l,&d)!=EOF){
double left=0,right=PI/2.0;
double mid,mmid;//角度为汽车靠近墙的一边和水平线的夹角
int size=100;
while(size--){//三分角度求出当H最大时的角度
mid=(left+right)/2.0;
mmid=(mid+right)/2.0;
double h1=getH(mid),h2=getH(mmid);
if(h1>h2)
right=mmid;
else
left=mid;
}
if(getH(left)<=y)
printf("yes\n");
else
printf("no\n");
}
return 0;
}