HDU2438:Turn the corner(三分)

时间:2021-06-13 10:16:29

传送门

分析

HDU2438:Turn the corner(三分)

根据这张图,我们只要使得h<=y即可,可以发现h是一个凸函数,故使用三分,具体见代码

代码

#include<cstdio>
#include<cstring>
#include<vector>
#include<algorithm>
using namespace std;
const double eps = 1e-7;
const double pi = acos(-1.0);
#define ll long long
#define F(i,a,b) for(int i=a;i<=b;++i)
#define R(i,a,b) for(int i=a;i<b;++i)
#define mem(a,b) memset(a,b,sizeof(a))
#pragma comment(linker, "/STACK:102400000,102400000")
inline void read(int &x){x=0; char ch=getchar();while(ch<'0') ch=getchar();while(ch>='0'){x=x*10+ch-48; ch=getchar();}} double x,y,l,w;
double calc(double ret)
{
double s,h;
s=l*cos(ret)+w*sin(ret)-x;
h=s*tan(ret)+w*cos(ret);
return h;
}
int main()
{
while(scanf("%lf%lf%lf%lf",&x,&y,&l,&w)!=EOF)
{
double left=0,right=pi/2;
while(right-left>eps)
{
double lm=left+(right-left)/3.0;
double rm=right-(right-left)/3.0;
if(calc(lm)<calc(rm)) left=lm;
else right=rm;
}
if(calc(left)<=y) puts("yes");else puts("no");
}
}