HDU 2438 Turn the corner 三角函数+三分查找法
来源:互联网 发布:知妈妈乐疯狂 编辑:程序博客网 时间:2024/06/07 02:16
题目地址:点击打开链接
Turn the corner
Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 3276 Accepted Submission(s): 1346
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?
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.
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 410 6 14.5 4
Sample Output
yesno
【题意】:车子要成功拐过这个弯道,最好的办法是使得车子的一条侧边靠墙走(然而现实中不存在);
【解析】:
根据图示,车子右侧沿着内拐角,左外侧沿着左侧墙壁。根据图中角度关系,即可得出关于h的函数,角度变化范围(0~90度)。
易得,函数是先增后减的。
用三分查找法找到函数h的最大值。最大值和y比较一下,会不会撞墙
【代码】:
#include<stdio.h>#include<math.h>double x,y,l,d;const double PI=3.14159;double h(double a){return d*cos(a)+d*sin(a)*sin(a)/cos(a)+l*cos(a)*tan(a)-x*tan(a);}int main(){while(~scanf("%lf%lf%lf%lf",&x,&y,&l,&d)){double m=0;double n=PI/2;double P,Q;while(fabs(m-n)>1e-6){P=m+(n-m)/3;Q=n-(n-m)/3;if(h(P)>h(Q))//左边大{n=Q;}else{m=P;}}if(h(m)<=y)puts("yes");elseputs("no");}return 0;}
阅读全文
0 0
- HDU 2438 Turn the corner 三角函数+三分查找法
- HDU 2438 Turn the corner(三分查找, 几何求解)
- 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【三分】
- HDU 2438 Turn the corner(三分)
- HDU 2438 Turn the corner 三分
- (step4.1.3)hdu 2438(Turn the corner——三分查找)
- HDU 2438 Turn the corner(三分枚举角度)
- HDU 2438 Turn the corner (计算几何 + 三分)
- hdu 2438 计算几何 三分 Turn the corner
- HDU ACM 2438 ->Turn the corner 三分求最值
- HDU 2438 Turn the corner 计算几何+三分
- 直接插入排序-java实现
- 怎么用弱引用实现内存泄漏检测
- bash: yum install crontabs: command not found
- 1.2.3休眠(Sleeping)
- C++黑框闪退解决措施
- HDU 2438 Turn the corner 三角函数+三分查找法
- leetcode解题报告19. Remove Nth Node From End of List
- 2017 山东理工第九届校赛 J LL
- Text Generation With LSTM Recurrent Neural Networks in Python with Keras
- 1.3总结
- JS原生数据类型检测
- Opencv学习——图像阈值化
- USCAO-Section 1.3 Ski Course Design
- C/C++中检查变量类型函数typeid()