HDU2438 Turn the corner【三分法】【数学几何】
来源:互联网 发布:快乐十分软件下载 编辑:程序博客网 时间:2024/04/29 01:59
Turn the corner
Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1930 Accepted Submission(s): 736
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 4
10 6 14.5 4
Sample Output
yes
no
题目大意:有一个直角拐角,给你水平道路宽度Y和竖直高度X,再给你汽车的长l,宽w
问:汽车是否能通过这个拐角。
思路:如果汽车的宽度大于水平道路宽度Y或是竖直高度X,无论如何都通不过。接下来
考虑一般情况。
如图:若汽车最左边与墙一直靠紧,则只需要判断右边最高点是否超过了Y。
设θ为汽车与水平方向的夹角,s为汽车最右边的角到拐点的水平距离。那么
s = l*cos(θ) + w*sin(θ) - x,从而得出 h = s*tan(θ)+w*cos(θ)。
θ角从0~π/2,变化,h则从低到高再到底,且是一个凸形函数。利用三分方法
得到最高点的h,与Y比较判断是否能通过。
#include<iostream>#include<algorithm>#include<cstdio>#include<cstring>#include<cmath>using namespace std;const double PI = acos(-1.0);double x,y,l,w;double calc(double angle){ double s = l*cos(angle) + w*sin(angle) - x; double h = s*tan(angle) + w*cos(angle); return h;}int main(){ while(cin >> x >> y >> l >> w) { double left,right,mid,midmid; left = 0; right = PI/2; while(right-left >= 1e-7) { mid = (left+right)/2; midmid = (mid+right)/2; if(calc(mid) > calc(midmid)) right = midmid; else left = mid; } if(x<w || y<w || calc(mid) > y) cout << "no" << endl; else cout << "yes" << endl; } return 0;}
0 0
- HDU2438 Turn the corner【三分法】【数学几何】
- hdu2438 Turn the corner 几何 三分法
- HDU2438 Turn the corner
- hdu2438 Turn the corner
- hdu2438 Turn the corner 三分
- Turn the corner(hdu2438三分)
- HDU2438 Turn the corner(三分)
- Turn the corner+三分法
- Turn the corner--hdu2438(3分法)
- HDU 2438 Turn the corner 三分法
- 2438 Turn the corner(数学题,三分法)
- hdoj2438Turn the corner【三分法】
- HDU 2438 Turn the corner (计算几何 + 三分)
- hdu 2438 计算几何 三分 Turn the corner
- HDU 2438 Turn the corner 计算几何+三分
- hdu 2348 Turn the corner(三分&&几何)(中等)
- hdoj 2438 Turn the corner (三分搜索+计算几何)
- HD 2438 Turn the corner (三分&&计算几何&&经典问题)
- KVM 虚拟机在 IBM System x 上应用
- 学院程设班级对抗赛总结
- C# 引用的实质
- 条款 45: 弄清 C++在幕后为你所写、所调用的函数
- 工业水处理:威立雅工业污水处理技术
- HDU2438 Turn the corner【三分法】【数学几何】
- QThread类基本操作 (补充)
- ceph存储 ceph集群线程池实现
- ActionScript 3 日积月累之一
- 右键添加当前窗口打开cmd
- linux nfs安装配置
- 工业水处理:威立雅焦化废水处理技术应用现状剖析
- 事件、委托、继承、线程综合利用
- centos 7 network card name change