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

本文共 1599 字,大约阅读时间需要 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 }

 

转载地址:http://lrivl.baihongyu.com/

你可能感兴趣的文章
脚本-if 根据学生考试成绩判断学生的优劣成绩
查看>>
HSRP和stp协议
查看>>
4月16日作业
查看>>
数据库连接池性能比对(hikari druid c3p0 dbcp jdbc)
查看>>
BeagleBone Black 之官方Debian系统安装
查看>>
linux解压缩命令
查看>>
计算机专业学生在毕业之前应该做的10000件事
查看>>
Hadoop1.2.1安装笔记3:hadoop配置
查看>>
mysql select是否会锁表 ?
查看>>
lamp自动安装脚本
查看>>
shell中的多进程【并发】
查看>>
LINUX新手入门-装Red Hat 5 系统和vm-tools
查看>>
数据库复习笔记(一)
查看>>
Windows消息机制
查看>>
python字符串运算符
查看>>
类型限定词
查看>>
关于R类的说明
查看>>
APUE读书笔记-10信号-01简介
查看>>
ITIL即IT基础架构库
查看>>
502 503 504
查看>>