HDU 2438——三分求值
来源:互联网 发布:淘宝秒杀成功吗 编辑:程序博客网 时间:2024/05/22 04:57
题目链接:
http://acm.hdu.edu.cn/showproblem.php?pid=2438
题目大意:
转弯,给定汽车的长度L和宽度D,以及转弯处马路的宽度X和Y,问汽车能否从这里转过去。
解题思路:
这个题目应该考虑一些极限情况,就是汽车靠着外侧角的两条边行驶过去。
如上图所示。那么我们可以求得汽车外侧的直线的方程,即图中红色的直线的方程。
y=xtan(t)+L*sin(t)+D/cos(t);
马路内侧点的坐标为(-Y,X)。将该点的x坐标带入方程可以得到y关于角度的函数:
y=-Y*tan(t)+L*sin(t)+D/cos(t);
y关于t是一个凸函数,通过三分我们可以求得y的最大值,
然后将该最大值与题目给定的X进行比较,得到结果。
源代码:
#include<stdio.h>#include<string.h>#include<stdlib.h>#include<math.h>#include<set>#include<map>#include<vector>#include<algorithm>#define INF 0x3f3f3f3fusing namespace std;typedef long long LL;const double eps=1e-8;const double PI=acos(-1.0);double X,Y,L,D; //马路的宽度,汽车的长和宽double l,r,ll,rr;double cal(double t) //角度{ return Y*tan(t)*(-1)+L*sin(t)+D/cos(t);}int main(){freopen("in.txt","r",stdin);while(scanf("%lf%lf%lf%lf",&X,&Y,&L,&D)==4){ l=0; r=PI/2; if(D>X || D>Y) //这个地方的特判是不可少的 { printf("no\n"); continue; } while(r-l>eps) { ll=l+(r-l)/3; rr=l+(r-l)*2/3; if(cal(ll)<cal(rr)) l=ll; else r=rr; } if(cal(r)<=X) //坐标 printf("yes\n"); else printf("no\n");}return 0;}
- HDU 2438——三分求值
- HDU 2438 三分
- HDU 2438 (三分)
- 三分求最小值——HDU 2241
- hdu-2438 计算几何+三分
- HDU 2438 求函数+三分
- (step4.1.3)hdu 2438(Turn the corner——三分查找)
- hdu 2438+hdu 3400(三分求极值)
- hdu 3400-三分套三分
- HDOJ/HDU 2438 计算几何+三分
- hdu 2438 - Turn the corner(三分)
- hdu 2438Turn the corner(三分)
- HDU 2438 Turn the corner(三分)
- hdu 2438 Turn the corner(三分)
- HDU 2438 Turn the corner(三分)
- hdu-2438-Turn the corner(三分)
- HDU 2438 Turn the corner 三分
- HDU 2438 Turn the corner【三分】
- MySQL数据库定时备份Shell脚本并备份至其它机器方法
- Codeforces Round #192 (Div. 2) A题
- win7升级ie到ie10后打不开的解决办法
- Linux下grep命令的用法
- 在不破坏背景的情况下实现动态文字
- HDU 2438——三分求值
- 盘点jdk各版本的新特性和一些专用术语
- 转:28岁创业者:1000万美金卖出应用的秘诀
- Android 应用程序之间内容分享详解(一)
- android 登录功能简介 获取EditText值进行比较
- java系列之 原生数据类型
- Linux基础知识之visudo精确用户赋权(sudo)
- Haswell 事务内存相关的一些资源介绍
- jsp语法