hdu2438 Turn the corner
2015-11-25 15:15
411 查看
Turn the corner
Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1613 Accepted Submission(s): 599
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?
Input
Every line has four real numbers, x, y, l and w.
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 4
10 6 14.5 4
Sample Output
yes
no
解题思路:
关键是要找到小车的运动状态,下面是分析和公式推导;
在小车转弯过程中,黄线是不断地变化的,变化规律是先增大再减小。所以抓住这一点,用三分法。先找一个变量,角度sita(就是上图中用红色标记的那个角),之后就是一系列的推导,算出黄线的长度。角度的范围是(0,pi/2)。
当三分找出最长的黄线长度之后,使之与Y做比较,当它小于Y时,就说明能够通过了
#include<cstdio> #include<cstring> #include<cmath> #include<iostream> #define pi 3.1415926 #define esp 1e-8 double x,y,l,d; double slove(double sita,double l,double x,double d) { return l*sin(sita)-x*tan(sita)+d/cos(sita); } int main() { while(scanf("%lf %lf %lf %lf",&x,&y,&l,&d)!=EOF) { double sita_left=0.0; double sita_right=pi/2.0; double mid,midmid; double mid_value; double midmid_value; while((sita_right-sita_left)>=esp) { mid=(sita_left+sita_right)/2.0; midmid=(mid+sita_right)/2.0; mid_value=slove(mid,l,x,d); midmid_value=slove(midmid,l,x,d); if(mid_value>midmid_value) sita_right=midmid; else sita_left=mid; } if((y-mid_value)>esp) printf("yes\n"); else printf("no\n"); } return 0; }
相关文章推荐
- SDWebImage异步加载图片及缓存的管理与清理
- iOS缓存方案
- winform Treeview设置右键点击的节点
- @CentOS安装MySQL
- 支付宝移动支付开发详细教程服务端采用.net mvc webapi(C#)
- jquery插件下载地址
- Android 锁屏状态/锁屏密码等相关
- CriminalIntent项目开发笔记(四)----使用fragment argument
- Spark开发指南Spark Programming Guide
- 一个丝滑的全屏滑动返回手势
- iOS 中gzip压缩不使用asi的方法
- 【Python网络爬虫】百度贴吧/豆瓣小组
- Android使用Unity导致Activity被销毁的解决办法
- HRESULT:0x80029C4A错误
- git中报unable to auto-detect email address 错误的解决拌办法
- java 正则表达式的应用:读取文件,获取其中的电话号码
- bootstrap学习和使用的经验总结
- CEO、COO、CFO、CTO
- 学习数据结构与算法分析如何帮助您成为更优秀的开发人员
- 判断条件问题是否存在