题意:奇异矩阵 使范式最大的最小
#include <iostream>
#include <stdio.h>
#include <string.h>
#include<algorithm>
#include<cmath>
using namespace std;
double a, b, c, d;
double max1;
double min1;
double max2;
double min2;
void fun1(double a1,double a2,double b1,double b2)
{
double q[4];
q[0] = a1*b1;
q[1] = a1*b2;
q[2] = a2*b1;
q[3] = a2*b2;
sort(q, q + 4);
max1 = q[3];
min1 = q[0];
}
void fun2(double a1, double a2, double b1, double b2)
{
double q[4];
q[0] = a1*b1;
q[1] = a1*b2;
q[2] = a2*b1;
q[3] = a2*b2;
sort(q, q + 4);
max2 = q[3];
min2 = q[0];
}
bool cmp(double a1, double a2, double a3)
{
if (a3 >= a1&&a3 <= a2)
return true;//在范围内
return false;
}
bool check(double n)
{
double a1 = a + n;
double a2 = a - n;
double b1 = b + n;
double b2 = b - n;
double c1 = c + n;
double c2 = c - n;
double d1 = d + n;
double d2 = d - n;
fun1( a1, a2, d1, d2);
fun2(b1, b2, c1, c2);
if (cmp(min1, max1, min2) || cmp(min2,max2,min1))
return true;
return false;
}
int main()
{
scanf("%lf%lf%lf%lf", &a, &b, &c, &d);
double m=-2e10;
if (m < a)
{
m = a;
}
if (m < b)
{
m = b;
}
if (m < c)
{
m = c;
}
if (m <d)
{
m = d;
}
double left, right;
left = 0;
right = m;
double mid;
while (fabs(left -right)>0.0000001)//求的是最大里面最小的
{
mid = (left + right) / 2.0;
if (check(mid))//满足条件
{
right = mid;//大了
}
else
{
left = mid + 0.0000005;//小了
}
}
printf("%lf\n", right);
return 0;
}