参考了这个博客

#include<cstdio>
#include<algorithm>
#include<cstring>
#define Max(a,b,c,d) max(max(a,b),max(c,d))
#define Min(a,b,c,d) min(min(a,b),min(c,d))
using namespace std;
double a,b,c,d,l,r=1000000000,mid;
bool check(double lim)
{
double max_x=Max((a+lim)*(d+lim),(a-lim)*(d-lim),(a+lim)*(d-lim),(a-lim)*(d+lim));
double min_x=Min((a+lim)*(d+lim),(a-lim)*(d-lim),(a+lim)*(d-lim),(a-lim)*(d+lim));
double max_y=Max((b+lim)*(c+lim),(b+lim)*(c-lim),(b-lim)*(c-lim),(b-lim)*(c+lim));
double min_y=Min((b+lim)*(c+lim),(b+lim)*(c-lim),(b-lim)*(c-lim),(b-lim)*(c+lim));
if(max_x-min_y>=0&&min_x-max_y<=0)
return 1;
else return 0;
}
int main()
{
scanf("%lf%lf%lf%lf",&a,&b,&c,&d);
for (int i=1;i<=100;i++)
{
mid=(l+r)/2;
if (check(mid)) r=mid;
else l=mid;
}
printf("%.10lf",l);
return 0;
}
05-11 17:57