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. 阿里云linux centos 一键部署web环境--图文详解

    一.购买阿里云服务器ECS 1,登录阿里云,选择阿里云服务器ECS 2,创建实例 或 3,选好配置 4,完成配置 注:记住用户名和密码 二.一键配置linux环境 1,下载xshell,安装成功后,建 ...

  2. String类的构造方法(2)

    写了常见的几个而已. 1:new 一个String类的时候系统会自动传一个空构造 public String(); 注意: 当对象初始化是 null时 和 对象是 "" 时,两者是 ...

  3. Codeforce 854 A. Fraction

    A. Fraction time limit per test 1 second memory limit per test 512 megabytes input standard input ou ...

  4. CentOS更新源

    1.首先备份/etc/yum.repos.d/CentOS-Base.repo mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS ...

  5. 为什么要用深度学习来做个性化推荐 CTR 预估

    欢迎大家前往腾讯云技术社区,获取更多腾讯海量技术实践干货哦~ 作者:苏博览 深度学习应该这一两年计算机圈子里最热的一个词了.基于深度学习,工程师们在图像,语音,NLP等领域都取得了令人振奋的进展.而深 ...

  6. ASP.NET Core中如何调整HTTP请求大小的几种方式

    一.前言 一般的情况下,我们都无需调用HTTP请求的大小,只有在上传一些大文件,或者使用HTTP协议写入较大的值时(如调用WebService)才可能会调用HTTP最大请求值. 在ASP.NET Co ...

  7. 7-21(排序) PAT排名汇总

    计算机程序设计能力考试(Programming Ability Test,简称PAT)旨在通过统一组织的在线考试及自动评测方法客观地评判考生的算法设计与程序设计实现能力,科学的评价计算机程序设计人才, ...

  8. 《算法导论》学习总结 — XX.第22章 图的基本算法

    BFS(广搜): 广搜就是广度优先搜索,根据名字可以知道,是通过广度来遍历图,也就是层次遍历吧. 在这里以及下面的DFS(深搜),都用到了颜色WHITE,GRAY,BLACK,不过作用不同,具体分别再 ...

  9. MySQL show status 参数详解

    状态名 作用域 详细解释 Aborted_clients Global 由于客户端没有正确关闭连接导致客户端终止而中断的连接数 Aborted_connects Global 试图连接到MySQL服务 ...

  10. Java命令模式以及来自lambda的优化

    前言    设计模式是软件工程中一些问题的统一解决方案的模型,它的出现是为了解决一些普遍存在的,却不能被语言特性直接解决的问题,随着软件工程的发展,设计模式也会不断的进行更新,本文介绍的是经典设计模式 ...