标签:
题目大意:给你一个拐角,两边的路的宽度分别为x,y。汽车的长和宽分别为h,w。问你这个汽车否转弯成功。
解题思路:如图,枚举角度。
这是一个凸函数所以三分枚举角度。

10 6 13.5 4 10 6 14.5 4
yes no
#include <iostream>
#include<time.h>
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<string>
#include<cmath>
#include<map>
#define eps 1e-10
#define PI acos(-1)
using namespace std;
const int maxn = 220;
#define LL long long
double x, y, l, w;
double Del(double ang)
{
double s = l*cos(ang)+w*sin(ang)-x;
double h = s*tan(ang)+w*cos(ang);
return h;
}
int main()
{
while(cin >>x>>y>>l>>w)
{
double Max = 0.0;
double left = 0;
double right = PI/2.0;
while(right-left > eps)
{
double mid = (right+left)/2.0;
double rmid = (mid+right)/2.0;
double xp1 = Del(mid);
double xp2 = Del(rmid);
if(xp1 > xp2) right = rmid;
else left = mid;
Max = max(Max, max(xp1, xp2));
}
if(Max > y) cout<<"no"<<endl;
else cout<<"yes"<<endl;
}
}HDU 2438 Turn the corner(三分枚举角度)
标签:
原文地址:http://blog.csdn.net/xu12110501127/article/details/43409833