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
思路:
角度三分[0,90]--h先增大后减小(车先往上开,再往下开直到平行)
代码:
import java.util.Scanner;
public class Main {
static double x,y,l,w;
static double PI=Math.acos(-1.0);
static double exp=1e-8;
public static double cal(double angle){
double s=l*Math.cos(angle)+w*Math.sin(angle)-x;
double h=w*Math.cos(angle)+s*Math.tan(angle);
return h;
}
public static void main(String[] args) {
Scanner scan=new Scanner(System.in);
while(scan.hasNext()){
x=scan.nextDouble();
y=scan.nextDouble();
l=scan.nextDouble();
w=scan.nextDouble();
double l=0,r=PI/2;
while(r-l>=exp){
double m=(l+r)/2;
double mm=(m+r)/2;
if(cal(m)>cal(mm)){
r=mm;
}
else{
l=m;
}
}
if(cal(r)>y||x<w||y<w){
System.out.println("no");
}
else{
System.out.println("yes");
}
}
}
}