三分 Problem 1005 Turn the corner 车转向问题
来源:互联网 发布:俄勒冈大学建筑系 知乎 编辑:程序博客网 时间:2024/06/04 17:47
Problem ID:1005 Turn the corner
简单题意:一辆汽车由一条路转向另一条路,给出车的长度、宽度,当前路的宽度,以及将要进入的路的宽度。如果能够进入,输出“yes”,否则输出“no”。
解题思路形成过程:如图所示: 根据问题可知:s=l*cos(m)+w*sin(m)-x; h=s*tan(m)+w*cos(m); 当h(max)<=y时,可进入下一条路;否则不可以。
h随角的增大先增大后减小,属于凸函数,所以需要用三分法求出h的最大值。
感想:一定先弄清楚问题的逻辑条件,将问题转化成数学问题后再运用相应的算法思想。
注意考虑算式的函数形式以及函数的增减性。
代码:
#include<iostream>#include<cmath>#include<stdio.h>using namespace std;double pi=acos(-1.0); //利用反余弦求出π的精确值double x,y,l,w;double cal(double m){ double s,h; s=l*cos(m)+w*sin(m)-x; h=s*tan(m)+w*cos(m); return h;}int main(){ freopen("2.txt","r",stdin); while(scanf("%lf %lf %lf %lf",&x,&y,&l,&w)!=EOF) { double ll=0,rr=pi/2; while(rr-ll>1e-9) { double mid=(ll+rr)/2; double midmid=(mid+rr)/2;//三分 if(cal(mid)>cal(midmid)) rr=midmid; else ll=mid; } if(cal(ll)<y) printf("yes\n"); else printf("no\n"); }}
1 0
- 三分 Problem 1005 Turn the corner 车转向问题
- hdu2438 Turn the corner 三分
- Turn the corner(hdu2438三分)
- HDU2438 Turn the corner(三分)
- HDU_P2438 Turn the corner(三分)
- Turn the corner(三分)
- Turn the corner(三分)
- HD 2438 Turn the corner (三分&&计算几何&&经典问题)
- heru 5081 Turn the corner(三分)
- 13.04.07 Turn the corner (三分)
- hdu 2438 - Turn the corner(三分)
- hdu 2438Turn the corner(三分)
- HDU 2438 Turn the corner(三分)
- Turn the corner+hdu+三分搜索
- hdu 2483 Turn the corner(三分)
- hdu 2438 Turn the corner(三分)
- HDU 2438 Turn the corner(三分)
- hdu-2438-Turn the corner(三分)
- 隐式类型转换
- AlertDialog和ProgressDialog
- 博主2000年真实遇鬼记-仅作记录以供后人参考
- 【排序算法】交换排序(C++实现)
- Android Socket 聊天室
- 三分 Problem 1005 Turn the corner 车转向问题
- java区别(String)和toString()的区别
- HDU 5667 Sequence
- 在浏览器中播放m3u8
- 计算字符个数之机试
- web编程的纯理论个人杂乱的笔记
- 不用循环和递归输出0-999的数
- 内存引用计数
- 第五章、理解RemoteView