因为只能选择一条边进行增长 我们选择最小的一条边进行增加
接着发现增加后的面积要么是单峰函数 要么是单调函数
所以运用三分法去解决
#include<bits/stdc++.h>
using namespace std;
#define lowbit(x) x&(-x)
#define ll long long
int T;
double eps=1e-8;
double s(double aa,double bb,double cc){
double p=(aa+bb+cc)/2;
return sqrt(p*(p-aa)*(p-bb)*(p-cc));
}
double calc()
{
int a,b,c,k;
double minn,l,r;
cin>>a>>b>>c>>k;
minn=min(a,min(b,c));
if(a==minn){
l=a;r=min(b+c,a+k);
}
else if(b==minn){
l=b;r=min(a+c,b+k);
b=a;
}
else {
l=c;r=min(a+b,c+k);
c=b;b=a;
}
double mid,midmid;
while(r - l > eps)
{
mid = (l + r)/2.0;
midmid = (r + mid)/2.0;
if(s(mid,b,c) >=s(midmid,b,c))
r = midmid;
else l = mid;
}
cout<<s(l,b,c)<<endl;
}
int main(){
freopen("sticks.in","r",stdin);
cin>>T;
while(T--)calc();
return 0;
}