博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Turn the corner (三分)
阅读量:4515 次
发布时间:2019-06-08

本文共 1672 字,大约阅读时间需要 5 分钟。

Turn the corner

Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 151 Accepted Submission(s): 61
 
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 410 6 14.5 4
 
Sample Output
yesno
 

汽车拐弯问题,给定X, Y, l, d判断是否能够拐弯。

我们发现随着角度θ的增大,最大高度h先增长后减小,即为凸性函数,可以用三分法来求解。

这里的Calc函数需要比较繁琐的推倒公式:
s = l * cos(θ) + w * sin(θ) - x;
h = s * tan(θ) + w * cos(θ);
其中s为汽车最右边的点离拐角的水平距离, h为里拐点最高的距离, θ范围从0到90。

3分搜索法

 代码:

1 #include
2 #include
3 #include
4 const double pi=2*asin(1.0); 5 double x,y,l,d; 6 double geth(double an){ 7 double s,h; 8 s=l*cos(an)-x+d*sin(an);//应该是减x因为车头要对住墙,然后看车尾最高是否大于y 9 h=s*tan(an)+d*cos(an);10 return h;11 }12 double ABS(double a){13 return a>=0?a:-a;14 }15 void erfen(){16 double l=0,m,mm,r=pi/2;17 // printf("%lf\n",pi);18 while(ABS(r-l)>1e-10){19 m=(l+r)/2;20 mm=(m+r)/2;21 if(geth(m)>=geth(mm))r=mm;22 else l=m;23 }24 // printf("%lf\n",geth(m));25 if(geth(l)>y)puts("no");26 else puts("yes");27 }28 int main(){29 while(~scanf("%lf%lf%lf%lf",&x,&y,&l,&d)){30 erfen();31 }32 return 0;33 }

 

转载于:https://www.cnblogs.com/handsomecui/p/4860569.html

你可能感兴趣的文章
WPF学习笔记----注释标记,使用自定义资源字典(style)文件的流程
查看>>
元素定位的八大法则
查看>>
Sublime Text 3 使用小记
查看>>
总结Pycharm里面常用的快捷键
查看>>
util.promisify 的那些事儿
查看>>
配置phpstudy+phpstorm+xdebug环境
查看>>
BZOJ 1079 [SCOI2008]着色方案
查看>>
[Win8.1系统]双系统
查看>>
HDU 3899 树形DP
查看>>
继承上机作业
查看>>
设计模式 4/23 建造者模式
查看>>
Logging in Java
查看>>
leetcode算法:Distribute Candies
查看>>
机器学习之路: python 朴素贝叶斯分类器 MultinomialNB 预测新闻类别
查看>>
LINUX 忘记root密码
查看>>
json转换成Map
查看>>
MySQL查看当前用户、存储引擎、日志
查看>>
tpcc-mysql 系列二:进行TPCC测试
查看>>
将16进制的颜色值变成UIColor
查看>>
[转]magento 2 modes – 每种模式的特点及如何切换(翻译)
查看>>