hdu Turn the corner

这题是道三分的题,首先要分析满足条件的情况,这个就是平面几何的功夫了。要想车子能够转弯成功,最上面那个点到水平线的距离要小于等于y。这里h和s的公式就是利用平面几何的知识求出来的:s=l*cos(a)+w*sin(a)-x;s=l*cos(a)+w*sin(a)-x;其中s为最右边的那个点到拐角处的水平距离。因为角度和高度h满足凸函数的关系,因此想到利用角度采用三分的方法进行求解。
#include"iostream"
#include"stdio.h"
#include"algorithm"
#include"string.h"
#include"cmath"
#define exp 1e-8
#define pi acos(-1.0)
using namespace std;
double x,y,l,w;
double cal(double a)
{
double s=l*cos(a)+w*sin(a)-x;
double s=l*cos(a)+w*sin(a)-x;
return h;
}
int main()
{
while(scanf("%lf%lf%lf%lf",&x,&y,&l,&w)==)
{
double left=;
double right=pi/;;
double mid,midmid;//三分
while(abs(right-left)>exp)
{
mid=(right+left)/;
midmid=(mid+right)/;
if(cal(mid)>=cal(midmid)) right=midmid;
else left=mid;
}
if(cal(mid)<=y) cout<<"yes"<<endl;
else cout<<"no"<<endl;
}
return ;
}
hdu Turn the corner的更多相关文章
- HDU 2438 Turn the corner(三分查找)
托一个学弟的福,学了一下他的最简便三分写法,然后找了一道三分的题验证了下,AC了一题,写法确实方便,还是我太弱了,漫漫AC路!各路大神,以后你们有啥好的简便写法可以在博客下方留个言或私信我,谢谢了! ...
- hdu 2348 Turn the corner(三分&&几何)(中等)
Turn the corner Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- hdu 2438 Turn the corner [ 三分 ]
传送门 Turn the corner Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Othe ...
- hdu 2438Turn the corner 三分
Turn the corner Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)T ...
- Turn the corner (三分)
Turn the corner Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Tot ...
- 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 ...
- HDU2438 Turn the corner【三分法】【数学几何】
Turn the corner Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- hdu 2438 Turn the corner(几何+三分)
Problem Description Mr. West bought a new car! So he is travelling around the city. One day he comes ...
随机推荐
- net发送邮件
对于.NET而言,从2.0开始,发邮件已经是一件非常easy 的事了.下面我给出一个用C#群发邮件的实例,做了比较详细的注解,希望对有需要的朋友有所help.看了这篇BLOG,如果你还不会用.NET发 ...
- 61. 从1到n,共有n个数字,每个数字只出现一次。从中随机拿走一个数字x,请给出最快的方法,找到这个数字。如果随机拿走k(k>=2)个数字呢?[find k missing numbers from 1 to n]
[本文链接] http://www.cnblogs.com/hellogiser/p/find-k-missing-numbers-from-1-to-n.html [题目] 从1到n,共有n个数字 ...
- CodeForces - 407A
Triangle Time Limit: 1000MS Memory Limit: 262144KB 64bit IO Format: %I64d & %I64u Submit Sta ...
- [Android Pro] UI设计师不可不知的安卓屏幕知识
reference to : http://www.android100.org/html/201505/24/149342.html 不少设计师和工程师都被安卓设备纷繁的屏幕搞得晕头转向,我既做UI ...
- error: Refusing to undefine while domain managed save image exists
[root@ok libvirt]# virsh undefine win7 error: Refusing to undefine while domain managed save image e ...
- Tomcat JMX
http://tomcat.apache.org/tomcat-6.0-doc/monitoring.html#Enabling_JMX_Remote
- STL —— STL六大组件
注:以下内容摘自 http://blog.csdn.net/byxdaz/article/details/4633826 STL六大组件 容器(Container) 算法(Algorithm) 迭代器 ...
- [原]C# Winform 文件编码批量转换工具
在发布产品程序包时,往往需要对程序文件进行编码检查,写了一个可以批量修改文件编码格式的辅助工具,希望对有同样需求的童鞋有帮助. 1.程序界面: 2.核心代码: /// <summary> ...
- 【HTML5】Canvas画布
什么是 Canvas? HTML5 的 canvas 元素使用 JavaScript 在网页上绘制图像. 画布是一个矩形区域,您可以控制其每一像素. canvas 拥有多种绘制路径.矩形.圆形.字符以 ...
- php常用的日期时间操作
//把当前日期时间以指定的格式转成字符串 $date_out=date ( 'Y-m-d H:i:s', time () ); //把时间字符串改成时间戳 $aab=strtotime($date_o ...