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?

the corner" title="Turn 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
题意:西先生开始出去,遇到一个弯,让你求能不能拐过去;
解题思路:假设过弯时l与底边夹角为s,用三分求最理想过弯角度(用过弯过程中与转弯之后的宽度y相比较),找到最合适的角度,如果最合适的角度,转弯的宽度还是比y大就肯定转不过去,反之就能转过去;
感悟:寻找过弯条件是最难的,找到之后就简单多了,记录第二道三分题;
代码(G++
0ms):
#include

#include

#include

#define pi 3.141592653589793238

using namespace std;



double x,y,l,d;

double cal(double s)//进行三分的条件

{

    return
l*cos(s)+(d-x*cos(s))/(sin(s));

   
//l*cos(s)+(d-x*cos(s))/(sin(s))就是过弯过程中在y方向上的宽

}

int
main()

{

   
//freopen("in.txt", "r", stdin);

    double
left,right,mid,midmid;

   
while(scanf("%lf%lf%lf%lf",&x,&y,&l,&d)!=EOF)

    {

       
//printf("x=%.1f y=%.1f l=%.1f d=%.1f\n",x,y,l,d);

       
if(d>x||d>y)

       
{

           
printf("no\n");

           
continue;

       
}

       
left=0;

       
right=pi/2;//最大只能是pi/2,不可能倒着转弯吧

       
//printf("left=%.1f right=%.1f\n",left,right);

       
while (right-left>1e-10)

       
{

           
mid=(left+right)/2;

           
midmid=(mid+right)/2;

           
//printf("mid=%.4f mid mid=%.4f\n",mid,midmid);

           
if (cal(mid)>=cal(midmid))//过弯过程中在y方向上的宽,与y比较

               
right=midmid;

           
else left=mid;

       
}

       
//printf("right=%.1f\n",right);

       
if(cal(right)>y)//如果最大角度过弯时还是比y宽就肯定过不去

           
printf("no\n");

       
else

           
printf("yes\n");

    }

    return
0;

}

Turn the corner的更多相关文章

  1. Turn the corner (三分)

    Turn the corner Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Tot ...

  2. Turn the corner

    Turn the corner Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Tot ...

  3. HDU 2438 Turn the corner(三分查找)

    托一个学弟的福,学了一下他的最简便三分写法,然后找了一道三分的题验证了下,AC了一题,写法确实方便,还是我太弱了,漫漫AC路!各路大神,以后你们有啥好的简便写法可以在博客下方留个言或私信我,谢谢了! ...

  4. hdu 2348 Turn the corner(三分&&几何)(中等)

    Turn the corner Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  5. hdu 2438 Turn the corner [ 三分 ]

    传送门 Turn the corner Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Othe ...

  6. HDU2438 Turn the corner【三分法】【数学几何】

    Turn the corner Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  7. hdu 2438 Turn the corner(几何+三分)

    Problem Description Mr. West bought a new car! So he is travelling around the city. One day he comes ...

  8. 【三分法】hdu2438 Turn the corner

    Problem Description Mr. West bought a new car! So he is travelling around the city.One day he comes ...

  9. hdu Turn the corner

    这题是道三分的题,首先要分析满足条件的情况,这个就是平面几何的功夫了.要想车子能够转弯成功,最上面那个点到水平线的距离要小于等于y.这里h和s的公式就是利用平面几何的知识求出来的:s=l*cos(a) ...

随机推荐

  1. struts1.3整合spring2.5(将spring委托给struts方式)

    前提是配置完struts1.3 导包 spring-2.5.6.jar //spring核心包 spring-webmvc-struts-2.5.5.jar //struts整合spring使用 lo ...

  2. BZOJ2748_音量调节_KEY

    [HAOI2012]音量调节 Time Limit: 3 Sec Memory Limit: 128 MB Description 一个吉他手准备参加一场演出.他不喜欢在演出时始终使用同一个音量,所以 ...

  3. JAVA多线程--Thinking in java

    聊聊并发:http://ifeve.com/java-concurrency-thread-directory/ 阻塞状态: sleep  可中断利用 interrupt方法 wait IO  不可中 ...

  4. 如何解决Python.h:No such file or directory

    安装python2.7对应的dev sudo apt-get install python-dev 安装python3.6对应的dev sudo apt-get install python3-dev

  5. js如何判断一个对象为空

    今天碰到一个问题如何判断一个对象为空? 总结的方法如下: 1.使用jquery自带的$.isEmptyObject()函数. var data={}; console.log($.isEmptyObj ...

  6. Mysql的排他锁和共享锁

    今天看代码看到有select name from user where id = 1 for update,有点懵逼,完全没有见过,只能说自己见识少了,那就只能学习一下.先做一下基本知识了解(大部分都 ...

  7. ionic2+Angular2:套接口明细步骤,以登录功能为例

    1.在app.module.ts引用HttpModul,并在imports内引用.截图如下:   2.在src目录下新建http服务.命令行:ionic g provider HttpService ...

  8. SQL Server Compact/SQLite Toolbox 使用

    最近一个嵌入式的数据库用的SqlCe 需要导入到Sqlite, 网上查到了这个工具--SQL Server Compact/SQLite Toolbox.但是在使用的时候遇到了一点小曲折,记录下来给需 ...

  9. Python自学笔记-面向对象相关(Mr seven)

    ---恢复内容开始--- http://www.cnblogs.com/wupeiqi/articles/5433893.html 类的成员可以分为三大类:字段.方法和属性. 一.字段 字段包括:普通 ...

  10. iOS如何提高页面流畅度

    A.提高CPU性能 对象创建1.尽量用轻量的对象代替重量的对象,比如CALayer 比 UIView 要轻量许多,如果不考虑交互事件的话,可以选择CALayer.2.Storyboard和xib加载对 ...