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. Bootstrap笔记合集

    一. 为了简化操作,方便使用,Bootstrap通过定义四个类名来控制文本的对齐风格: ☑   .text-left:左对齐 ☑   .text-center:居中对齐 ☑   .text-right ...

  2. NameError: name 'messagebox' is not defined 错误处理

    写了段代码,想在按下button的时候跳个提示框出来,调试的时候提示了messagebox未定义 from tkinter import * def test_show(): messagebox.s ...

  3. 为什么你需要将代码迁移到ASP.NET Core 2.0?

    随着 .NET Core 2.0 的发布,.NET 开源跨平台迎来了新的时代.开发者们可以选择使用命令行.个人喜好的文本编辑器.Visual Studio 2017 15.3 和 Visual Stu ...

  4. 600集Python从入门到精通教程(懂中文就能学会)

    目录大纲: 本套教程15天 1-3   天内容为Linux基础命令 4-13  天内容为Python基础教程 14-15 天内容为 飞机大战项目演练 视频概括: 第一阶段(1-3天): 该阶段首先通过 ...

  5. [Java语言] 《struts2和spring MVC》的区别_动力节点

    1.Struts2是类级别的拦截, 一个类对应一个request上下文,SpringMVC是方法级别的拦截,一个方法对应一个request上下文,而方法同时又跟一个url对应,所以说从架构本身上Spr ...

  6. 【笔记】php常用函数

    phpusleep() 函数延迟代码执行若干微秒.unpack() 函数从二进制字符串对数据进行解包.uniqid() 函数基于以微秒计的当前时间,生成一个唯一的 ID.time_sleep_unti ...

  7. c#入门基础笔记

    1.1:.NET与C# 1.1.1:.NET概述与C#应用 .NET是位于WINDOWs平台的一种技术.包含能在.NET FRAMwork平台运行的所有编程. 1.1.2:IDE环境 微软退出强大的平 ...

  8. python中如何不区分大小写的判断一个元素是否在一个列表中

    python中判断某一个元素是否在一个列表中,可以使用关键字in 和 not in. 示例如下: 如果需要输出相应的信息,可以搭配使用if语句,这里不赘述. --------------------- ...

  9. 在项目中创建单元测试时junit的配置和使用

    首先配置项目中AndroidMainfest.xml文件,加入 <instrumentation android:name="android.test.InstrumentationT ...

  10. java程序调用存储过程和存储函数

    java程序调用存储过程 jdbcUtil.java文件 package cn.itcast.oracle.utils; import java.sql.Connection; import java ...