题目描述

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. ESFramework 4.0 性能测试

    本实验用于测试ESFramework服务端引擎的性能,测试程序使用ESFramework 4.0版本. 一.准备工作 测试的机器总共有3台,都是普通的PC,一台作为服务器,两台作为客户端. 作为服务器 ...

  2. LeetCode OJ 162. Find Peak Element

    A peak element is an element that is greater than its neighbors. Given an input array where num[i] ≠ ...

  3. Matlab - 矩阵基本操作

    1. 矩阵的输入 右值是用方括号表示: , 逗号或空格分隔元素     ; 分号分隔行 >> A = [-, ; , ] A = - 2. 矩阵的加减 >> C = A + B ...

  4. html5 读写sqlite数据库

    var db = openDatabase('MyData','','My Database',102400); //首先它创建一个数据库表,里面有3个字段 db.transaction(functi ...

  5. java的静态方法的使用

    静态的方法和属性,你可以这么理解,就是所有对象公用的,比如一个属性是这样定义的: private static String name; 那么他的意思就是说,因为他是静态的,我所有的对象的name属性 ...

  6. kvstore之mongodb为存储介质

    配置config(连接mongo) mongo define('KVSTORE_STORAGE', 'base_kvstore_mongodb'); define('MONGODB_SERVER_CO ...

  7. 运行CImg库笔记

    1. 在程序代码中加入 #include "CImg.h" using namespace cimg_library; 2. (1)Mac下 出现错误“无X11/Xlib.h”,: ...

  8. 拦截asp.net输出流做处理, 拦截HTML文本(asp.net webForm版)

    对已经生成了HTML的页面做一些输出到客户端之前的处理 方法的原理是:把Response的输出重定向到自定义的容器内,也就是我们的StringBuilder对象里,在HTML所有的向页面输出都变 成了 ...

  9. prestashop 基本设置

    不跳转 要先改这个UPDATE`ps_shop_url`SET`domain_ssl`= replace(`domain_ssl` ,'us2.try.net','www.gelchaussures. ...

  10. <转>如何高效快速看懂Android源码

    原网址:http://jingyan.baidu.com/article/574c5219ca78ed6c8d9dc12a.html 在Android系统上工作了一段时间,经常会遇到题目中的问题,下面 ...