标签:des style blog http ar io os sp java
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;
}
HDU2438 Turn the corner【三分法】【数学几何】
标签:des style blog http ar io os sp java
原文地址:http://blog.csdn.net/lianai911/article/details/41977693