首页 技术 正文
技术 2022年11月18日
0 收藏 492 点赞 3,413 浏览 1001 个字

题目描述

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

大意

求长为l,宽为w的汽车能否通过前后道路宽度依次为x与y的90度直角弯道

思考

很明显,这是一道数学题,公式的推导过程很是麻烦,我也是参考了题解才推导出正确的公式,主要参考了这篇博客

这是一个凸性函数,因此我用了三分搜素法来做

AC代码

  1. #include <iostream>
  2. #include <stdio.h>
  3. #include <math.h>
  4. using namespace std;
  5. double pi = acos(-1.0);
  6. double x,y,l,w,s,h;
  7. double cal(double a)
  8. {
  9. s = l*cos(a)+w*sin(a)-x;
  10. h = s*tan(a)+w*cos(a);
  11. return h;
  12. }
  13. int main()
  14. {
  15. double left,right,mid,midmid;
  16. while(scanf("%lf%lf%lf%lf",&x,&y,&l,&w)!=EOF)
  17. {
  18. left = 0.0;
  19. right = pi/2;
  20. while(fabs(right-left)>1e-8)
  21. {
  22. mid = (left+right)/2;
  23. midmid = (mid+right)/2;
  24. if(cal(mid)>=cal(midmid))right = midmid;
  25. else left = mid;
  26. }
  27. if(cal(mid)<=y)printf("yes\n");
  28. else printf("no\n");
  29. }
  30. return 0;
  31. }//三分法程序

做这道题好像做高中的数学题(不过好难)。。。。

来自为知笔记(Wiz)

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,082
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,556
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,405
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,179
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,815
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,898