HDU2438 Turn the corner【三分法】【数学几何】
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【三分法】【数学几何】的更多相关文章
- 【三分法】hdu2438 Turn the corner
Problem Description Mr. West bought a new car! So he is travelling around the city.One day he comes ...
- HDU2438:Turn the corner(三分)
传送门 分析 根据这张图,我们只要使得h<=y即可,可以发现h是一个凸函数,故使用三分,具体见代码 代码 #include<cstdio> #include<cstring&g ...
- hdu 2348 Turn the corner(三分&&几何)(中等)
Turn the corner Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- Turn the corner (三分)
Turn the corner Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Tot ...
- hdu 1577 WisKey的眼神 (数学几何)
WisKey的眼神 Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total S ...
- Turn the corner
Problem Description Mr. West bought a new car! So he is travelling around the city. One day he comes ...
- Turn the corner
Turn the corner Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Tot ...
- HDU 2438 Turn the corner(三分查找)
托一个学弟的福,学了一下他的最简便三分写法,然后找了一道三分的题验证了下,AC了一题,写法确实方便,还是我太弱了,漫漫AC路!各路大神,以后你们有啥好的简便写法可以在博客下方留个言或私信我,谢谢了! ...
- hdu 1115 Lifting the Stone (数学几何)
Lifting the Stone Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others ...
随机推荐
- .Net 自动属性结合手动属性
Model using System; using System.Collections.Generic; using System.Linq; using System.Web; namespace ...
- Socket编程中的强制关闭与优雅关闭及相关socket选项
以下描述主要是针对windows平台下的TCP socket而言. 首先需要区分一下关闭socket和关闭TCP连接的区别,关闭TCP连接是指TCP协议层的东西,就是两个TCP端之间交换了一些协议包( ...
- 使用h5 <a>标签 href='url' download 下载踩过的坑
用户点击下载多媒体文件(图片/视频等),最简单的方式: <a href='url' download="filename.ext">下载</a> 如果url ...
- Linux下截图技巧
在需要Linux显示图片的场合,最普通的方法,会考虑用数码相,或是用Vmware,或VPc来抓拍,这样以来会比较麻烦,Linux也自带了些工具例如Gimp,ksnapshot这里我介绍一 ...
- go 可以开发桌面应用
go 可以开发桌面应用 go 可以开发桌面应用,但并不是很舒适.可以使用的GUI库有:1.goqt,LiteIDE作者出品,Go和QT的绑定,还未发布2.go.uik,纯Go实现的并发UI工具3.wa ...
- Python datetime time 等时间 日期 之间的计算和相互转化
from datetime import datetime, date, timedelta, timezone from time import time, ctime, localtime, st ...
- 查看oracle数据库的启动时间
Oracle的sys用户下有个视图v_$instance,该视图只有一行数据.通过SQL语名可查询其内容: select * from sys.v_$instance 此视图可查看很多东西,如实例名, ...
- 自己定义控件的onMeasure方法具体解释
在我们自己定义控件的时候可能你会用到onMeasure方法,以下就具体的给大家介绍一下这种方法: @Override protected void onMeasure(int widthMeasure ...
- actionmode-ActionMode以及它的menu使用
下图左边效果为Context Menu右边效果为ActionMode. ActionMode 其实就是替换在actionbar的位置上显示的一个控件.它跟actionbar一样,也是一种导航作用.只不 ...
- 21. Node.Js Buffer类(缓冲区)-(一)
转自:https://blog.csdn.net/u011127019/article/details/52512242