题目分析
画图(红色线段为辅助线)。

S△DEF=S△ABC−(S△AEF+S△BDF+S△CDE)=S△ABC−[(1−p)S△ACF+(1−p)S△ABD+(1−p)S△BCE]=S△ABC−(1−p)[S△ACF+S△ABD+S△BCE]=S△ABC−(1−p)[pS△ABC+pS△ABC+pS△ABC]=S△ABC−3p(1−p)S△ABC=[1−3p(1−p)]S△ABC
∴ 取 [1−3p(1−p)] 最小,即取 p(1−p) 最大。
p(1−p)=(21−21+p)(21+21−p)=[21−(21−p)][21+(21−p)]=(21)2−(21−p)2
∴ 取 (21)2−(21−p)2 最大,即取 (21−p)2 最小,即取 21−p 最小。
∴ 当 l≤0.5≤r 时,取 p=0.5;当 r<0.5 时,取 p=r;当 l>0.5 时,取 p=l。
完整代码
建一个类 dot,程序中 A * B 表示 AB 的长度。根据样例,四舍五入到 1×10−12,即 dp=1×10−12。
C++#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
double l, r, p;
class dot{
public:
double x, y;
double operator * (const dot& that) const{
return sqrt((this->x - that.x) * (this->x - that.x) + (this->y - that.y) * (this->y - that.y));
}
}A, B, C;
double S(double a, double b, double c){
double _p = (a + b + c) / 2;
return sqrt(_p * (_p - a) * (_p - b) * (_p - c));
}
signed main(){
ios::sync_with_stdio(0), cin.tie(), cout.tie();
cin >> l >> r >> A.x >> A.y >> B.x >> B.y >> C.x >> C.y;
if (l > 0.5) p = l;
else if (r < 0.5) p = r;
else p = 0.5;
cout << fixed << setprecision(12) << S(B * C, C * A, A * B) * (1 - 3 * p * (1 - p));
return 0;
}