1:问题描述
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
10 6 13.5 4
10 6 14.5 4
Sample Output
yes
no
2:大致题意
有一辆车要从一个宽度为x的路上转到宽度为y的路上去。车的长度为l,宽度为w。
问是否可以转过去。
3:思路
得到以下的表达式:
s=l*cos(a)+w*sin(a)-x;
h=s*tan(a)+w*cos(a);
三分角度。得出h的最小值。
再判断h与y的关系。
4:感想
表达式好难求。。
要找各种关系。
5:ac代码
#include<iostream>
#include<string.h>
#include<set>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<numeric>
#include<math.h>
#include<string.h>
#include<sstream>
#include<stdio.h>
#include<string>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<map>
#include<queue>
#include<iomanip>
#include<cstdio>
using namespace std;
double PI=acos(-1.0);
double s,h,l,w,x,y;
double car(double a)
{
s=l*cos(a)+w*sin(a)-x;
h=s*tan(a)+w*cos(a);
return h;
}
int main()
{
//freopen("r.txt","r",stdin);
double right,left,m,mm;
while(cin>>x>>y>>l>>w)
{
left=0;
right=PI/2;
while(right-left>0.0000001)
{
m=(right+left)/2;
mm=(right+m)/2;
if(car(m)>=car(mm)) right=mm;
else left=m;
}
if(car(m)<=y) cout<<"yes"<<endl;
else cout<<"no"<<endl;
}
return 0;
}