Turn the corner


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

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

题目大意:有一个直角拐角,给你水平道路宽度Y和竖直高度X,再给你汽车的长l,宽w

问:汽车能否通过这个拐角。

思路:假设汽车的宽度大于水平道路宽度Y或是竖直高度X。不管怎样都通只是。接下来

考虑普通情况。

如图:若汽车最左边与墙一直靠紧,则仅仅须要推断右边最高点是否超过了Y。

设θ为汽车与水平方向的夹角,s为汽车最右边的角到拐点的水平距离。那么

s = l*cos(θ) + w*sin(θ)
- x,从而得出 h = s*tan(θ)+w*cos(θ)。

θ角从0~π/2,变化,h则从低到高再究竟,且是一个凸形函数。利用三分方法

得到最高点的h。与Y比較推断能否通过。

#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>
using namespace std;
const double PI = acos(-1.0);
double x,y,l,w;
double calc(double angle)
{
double s = l*cos(angle) + w*sin(angle) - x;
double h = s*tan(angle) + w*cos(angle);
return h;
}
int main()
{ while(cin >> x >> y >> l >> w)
{
double left,right,mid,midmid;
left = 0;
right = PI/2;
while(right-left >= 1e-7)
{
mid = (left+right)/2;
midmid = (mid+right)/2;
if(calc(mid) > calc(midmid))
right = midmid;
else
left = mid;
}
if(x<w || y<w || calc(mid) > y)
cout << "no" << endl;
else
cout << "yes" << endl;
} return 0;
}

HDU2438 Turn the corner【三分法】【数学几何】的更多相关文章

  1. 【三分法】hdu2438 Turn the corner

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

  2. HDU2438:Turn the corner(三分)

    传送门 分析 根据这张图,我们只要使得h<=y即可,可以发现h是一个凸函数,故使用三分,具体见代码 代码 #include<cstdio> #include<cstring&g ...

  3. hdu 2348 Turn the corner(三分&amp;&amp;几何)(中等)

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

  4. Turn the corner (三分)

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

  5. hdu 1577 WisKey的眼神 (数学几何)

    WisKey的眼神 Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total S ...

  6. Turn the corner

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

  7. Turn the corner

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

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

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

  9. hdu 1115 Lifting the Stone (数学几何)

    Lifting the Stone Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others ...

随机推荐

  1. hdu1856 More is better (并查集)

    More is better Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 327680/102400 K (Java/Others) ...

  2. JavaScript中获取Map集合中的key和value值(前提是:既不知道key为什么值,也不知道value有哪些值)

    for(var i in maps){//通过定义一个局部变量i遍历获取map里面的所有key值 alert(maps[i]); //通过获取key对应的value值 }

  3. jquery19 ajax()

    <!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Type" content ...

  4. Android 学习笔记之Bitmap位图的旋转

    位图的旋转也可以借助Matrix或者Canvas来实现. 通过postRotate方法设置旋转角度,然后用createBitmap方法创建一个经过旋转处理的Bitmap对象,最后用drawBitmap ...

  5. 57.C++处理转义字符

    #include <iostream> #include <string> #include <cstdlib> using namespace std; void ...

  6. 解决Not allowed to load local resource

    在做视频上传的时候,发现Not allowed to load local resource,也弄了很久,怕自己忘记了所以记下来 bind: function() { SelectVideo.on(& ...

  7. Java证书通信

    一.概念介绍:   加密是将数据资料加密,使得非法用户即使取得加密过的资料,也无法获取正确的资料内容,所以数据加密可以保护数据,防止监听攻击.其重点在于数据的安全性.身份认证是用来判断某个身份的真实性 ...

  8. mvc定时执行任务(获取气象台的气象数据,定时新增)

    1.定时任务: gloabl.asax文件Application_Start()方法注册: System.Timers.Timer t = new System.Timers.Timer(theInt ...

  9. Maven实战(五)——自己主动化Web应用集成測试

    自己主动化集成測试的角色 本专栏的上一篇文章讲述了Maven与持续集成的一些关系及详细实践,我们都知道,自己主动化測试是持续集成不可缺少的一部分,基本上,没有自己主动化測试的持续集成,都非常难称之为真 ...

  10. Chormium线程模型及应用指南

    核心概念 设计上遵循以下原则: 1 不要在UI线程做不论什么堵塞式的I/O操作,以及其他耗时的操作,通过消息传递把各种操作传给相应用途的线程去做. 2 不鼓舞线程加锁机制和线程安全对象. 对象仅仅存在 ...