题目描述

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. }//三分法程序

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

acm课程练习2--1005的更多相关文章

  1. ACM课程学习总结

    ACM课程学习总结报告 通过一个学期的ACM课程的学习,我学习了到了许多算法方面的知识,感受到了算法知识的精彩与博大,以及算法在解决问题时的巨大作用.此篇ACM课程学习总结报告将从以下方面展开: 学习 ...

  2. ACM课程总结

    当我还是一个被P哥哥忽悠来的无知少年时,以为编程只有C语言那么点东西,半个学期学完C语言的我以为天下无敌了,谁知自从有了杭电练习题之后,才发现自己简直就是渣渣--咳咳进入正题: STL篇: 成长为一名 ...

  3. 华东交通大学2016年ACM“双基”程序设计竞赛 1005

    Problem Description 最近侯ry感觉自己在数学方面的造诣不忍直视:他发现他的学习速率呈一个指数函数递增,疯狂的陷入学习的泥潭,无法自拔:他的队友发现了他的学习速率y=e^(b*lna ...

  4. acm课程练习2--1013(同1014)

    题目描述 There is a strange lift.The lift can stop can at every floor as you want, and there is a number ...

  5. acm课程练习2--1003

    题目描述 My birthday is coming up and traditionally I'm serving pie. Not just one pie, no, I have a numb ...

  6. acm课程练习2--1002

    题目描述 Now, here is a fuction:  F(x) = 6 * x^7+8x^6+7x^3+5x^2-yx (0 <= x <=100)Can you find the ...

  7. acm课程练习2--1001

    题目描述 Now,given the equation 8x^4 + 7x^3 + 2x^2 + 3x + 6 == Y,can you find its solution between 0 and ...

  8. 华东交通大学2015年ACM“双基”程序设计竞赛1005

    Problem E Time Limit : 3000/2000ms (Java/Other)   Memory Limit : 65535/32768K (Java/Other) Total Sub ...

  9. 华东交通大学2017年ACM“双基”程序设计竞赛 1005

    Problem Description 假设你有一个矩阵,有这样的运算A^(n+1) = A^(n)*A (*代表矩阵乘法)现在已知一个n*n矩阵A,S = A+A^2+A^3+...+A^k,输出S ...

随机推荐

  1. LeetCode OJ 4. Median of Two Sorted Arrays

    There are two sorted arrays nums1 and nums2 of size m and n respectively. Find the median of the two ...

  2. clion idea jetbrain windows下搞c/c++

    安装 clion 把MinGW(搜MinGW.zip)放到c盘根目录下 ok

  3. chapter9_3 协同程序实现迭代器

    将循环迭代器视为"生产者-消费者"模式的一种特例:迭代器产生的数据供循环体消费. 因此,用协同程序写迭代器就理所当然了.因为协同程序可以一改传统调用者与被调用者之间的关系. 有了这 ...

  4. Openjudge-计算概论(A)-计算书费

    描述: 下面是一个图书的单价表:计算概论 28.9 元/本数据结构与算法 32.7 元/本数字逻辑 45.6元/本C++程序设计教程 78 元/本人工智能 35 元/本计算机体系结构 86.2 元/本 ...

  5. 【Linux】zookeeper构造伪集群

    1.在一台机器装安装3个zk server,构建伪集群模式安装步骤如下:1.下载zookeeper,下载地址:http://mirror.bit.edu.cn/apache/zookeeper/zoo ...

  6. Bug(案例)图片的垂直出现隐藏

    这个案例是一个出Bug的案例,很抱歉本人没有找到bug在哪,但是功能却实现了. <!DOCTYPE html> <html> <head> <meta cha ...

  7. apache与php安装

    安装库文件 yum install -y pcre pcre-devel apr apr-deve 安装apache cd /usr/local/src/httpd-2.4.23 Bundled AP ...

  8. eclipse代码提示优化

    用Eclipse编写Android程序的代码提示功能主要是在java和xml文件中,有时候会失效,默认的提示功能有限. 1)java文件自动提示      Window->Preferences ...

  9. C语言_cmd_pause

    再C语言里面使用system函数调用pause. system("pause"); 会显示   请按任意键继续. . . system("pause ->nul&q ...

  10. VBS基础篇 - 对象(6) - Folder对象

    VBS基础篇 - 对象(6) - Folder对象   描述:提供对文件所有属性的访问,从FSO对象的GetFile方法获得 使用Folder对象 要用Folder对象模型来编程必须先用FSO对象的G ...