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 ... 
随机推荐
- iOS xib中TableView创建的2种模式
			在xcode 5.0中 用xib编辑tableview有2种模式,见下图 其中,dynamic prototype 动态原型 表示tableview会询问它指定的 data source获取数据,如果 ... 
- iOS 中NSOperationQueue,Grand Central Dispatch , Thread的上下关系和区别
			In OS X v10.6 and later, operation queues use the libdispatch library (also known as Grand Central D ... 
- jQuery操作复选框的简单使用
			开发中为了实现一个小功能,就是复选框的相互影响事件,如下图: 就是通过复选框设置权限,权限是分等级的,这是一个web管理系统的应用,一个管理员具有三个权限赋予,权限也是有等级的,其中删除和编辑权限相当 ... 
- BestCoder15 1002.Instruction(hdu 5083) 解题报告
			题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5083 题目意思:如果给出 instruction 就需要输出对应的 16-bit binary cod ... 
- Paths on a Grid(poj 1942)
			给定一个矩形网格的长m和高n,其中m和n都是unsigned int32类型,一格代表一个单位,就是一步,求从左下角到右上角有多少种走法,每步只能向上或者向右走. //注意循环的时候,要循环小的数,否 ... 
- cf112a(水题)
			题目很简单..不过题意好像有点难懂... 题意:判定一个数能否被一个幸运数整除,循环一遍4到n/4,若存在i为幸运数且被n整除输出yes,反之输出no... 代码如下: #include <bi ... 
- C#对XML进行操作(添加、修改)
			XML文档内容如下: <?xml version="1.0" encoding="utf-8"?> <root> <first i ... 
- snmp v3
			http://blog.chinaunix.net/xmlrpc.php?r=blog/article&uid=7654720&id=3355515 http://tydldd.ite ... 
- 面向服务的体系结构(SOA)——(2)ESB介绍及职责
			企业服务总线(Enterprise Service Bus)是SOA的基础设施,之所以这么说是因为要达到SOA的目标(增强灵活性)就必须有调用服务的方法,ESB的存在有效的保证了消费者能够调用供应者提 ... 
- 输入文本框,当点击enter时,做进一步处理!
			//登录用户文本框敲回车键 private void txtCode_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.En ... 
