• Turn the corner--hdu2438(3分法)


     

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


    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
     
     
     
    分析:这个题就是看车子是否能通过这个转角!
     
     
     
    如图分析,如果h最大的时候还是小于y的,那么车一定能通过!
    即变相的求函数h=l*sin(a)-x*tan(a)+d/cos(a)的最大值,显然用三分法!
     1 #include<stdio.h>
     2 #include<math.h>
     3 #define PI 3.1415926535
     4 double l,d,x,y;
     5 double hs(double p)
     6 {
     7     double w;
     8     w=l*sin(p)-x*tan(p)+d/cos(p);//函数,计算h
     9     return w;
    10 }
    11 int main()
    12 {
    13     while(scanf("%lf%lf%lf%lf",&x,&y,&l,&d)!=EOF)
    14     {
    15     double a=0,b=PI/2,mid,midmid;
    16     do
    17     {
    18         //mid=(b-a)/3+a;
    19         //midmid=(b-a)*2/3+a;
    20         mid=(a+b)/2;
    21         midmid=(mid+b)/2;
    22         if(hs(mid)>hs(midmid))
    23         b=midmid;
    24         else
    25         a=mid;
    26     }while(b-a>1e-10);
    27     if(hs(mid)<y)
    28     printf("yes
    ");
    29     else
    30     printf("no
    ");
    31     }
    32     return 0;
    33 }
  • 相关阅读:
    $('div div')和$('div >div')的区别
    [转]35岁前程序员要规划好的四件事,健康居首位
    程序员应该改变的20个思维习惯
    JQuery总结
    Javahome 与 Path 与ClassPath的含义
    jsp 位置
    访问 IIS 元数据库失败 权限问题
    xp添加文件夹写入权限
    dataset 对象
    js的一些代码
  • 原文地址:https://www.cnblogs.com/Eric-keke/p/4679082.html
Copyright © 2020-2023  润新知