Turn the corner
TimeLimit: 1 Second MemoryLimit: 32 Megabyte
Totalsubmit: 661 Accepted: 184
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
double Cal(double L)
{
double s = l * cos(L) + w * sin(L) - x;
double h = s * tan(L) + w * cos(L);
return h;
}
#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;
#define PI 3.1415926535897932384626
const double EPS = 1e-10;
double x,y,l,w;
double Cal(double L)
{
double s = l * cos(L) + w * sin(L) - x;
double h = s * tan(L) + w * cos(L);
return h;
}
double Solve(void)
{
double Left, Right;
double mid, midmid;
double mid_value, midmid_value;
Left = 0; Right = PI*0.5;
while (Left + EPS < Right)
{
mid = (Left + Right) / 2;
midmid = (mid + Right) / 2;
mid_value = Cal(mid);
midmid_value = Cal(midmid);
if (mid_value >= midmid_value) Right = midmid;
else Left = mid;
}
return Cal(Left);
}
int main()
{
freopen("in.txt","r",stdin);
while(cin>>x>>y>>l>>w)
{
if(x<w||y<w) cout<<"no"<<endl;
else
{
double H = Solve();
if(H>0&&H<y) cout<<"yes"<<endl;
else cout<<"no"<<endl;
}
}
return 0;
}