HOJ 2438 Turn the corner

简单三分

Turn the corner

Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 2272    Accepted Submission(s): 876


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?
HOJ 2438 Turn the corner_第1张图片
 

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
 

Source
2008 Asia Harbin Regional Contest Online
 

主要是算出拐弯时高度H。写成函数。
#include
#include
#include
#include
#include
#include

using namespace std;

#define fi acos(-1.0)

double l,d,x,y;

//核心代码
double cal(double a)
{
    return (l*cos(a)-x)*tan(a)+d/cos(a);
}

int main()
{
  while(scanf("%lf%lf%lf%lf",&x,&y,&l,&d)!=EOF)
  {
      double left=0.0,mid,midmid,right=fi/2;
      if(d>=y||d>=x)//    减少时间复杂度
      {
          cout<<"no"<1e-7)//三分代码
      {
          mid=(right+left)/2;
          midmid=(mid+right)/2;
          if(cal(mid)>=cal(midmid))
            right=midmid;
          else
            left=mid;
      }
      if(cal(midmid)>y)
        //puts("no");
        cout<<"no"<

你可能感兴趣的:(算法)