「QFOI R2」寺秋山霭苍苍 官方题解
考查内容:
- 【1】代数(初中部分)。
- 【1】几何(初中部分)。
- 【3】平方根函数。
本文将介绍两种较为简单的方法。
方法一
容易由海伦公式计算出
根据三角形面积公式
用割补法可以得到
注意到
inline double calc(double S, double p) {
return S - 3.0 * (S * p * (1.0 - p));
}
double l, r, x1, y1, x2, y2, x3, y3;
cin >> l >> r >> x1 >> y1 >> x2 >> y2 >> x3 >> y3;
double a = sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
double b = sqrt((x1 - x3) * (x1 - x3) + (y1 - y3) * (y1 - y3));
double c = sqrt((x2 - x3) * (x2 - x3) + (y2 - y3) * (y2 - y3));
double p = (a + b + c) * 0.5;
double S = sqrt(p * (p - a) * (p - b) * (p - c));
double k = 0.5;
k = min(k, r);
k = max(k, l);
cout << fixed << setprecision(12) << calc(S, k) << endl;
方法二
令
根据方法一中的证明,精度
const double eps = 1e-9;
inline double calc(double x1, double y1, double x2, double y2, double x3, double y3) {
double a = sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
double b = sqrt((x1 - x3) * (x1 - x3) + (y1 - y3) * (y1 - y3));
double c = sqrt((x2 - x3) * (x2 - x3) + (y2 - y3) * (y2 - y3));
double p = (a + b + c) * 0.5;
double S = sqrt(p * (p - a) * (p - b) * (p - c));
return S;
}
double l, r, x1, y1, x2, y2, x3, y3;
cin >> l >> r >> x1 >> y1 >> x2 >> y2 >> x3 >> y3;
double S = 1e100;
for(double k = l; k <= r + eps; k += 0.01) {
double x4 = x1 + (x2 - x1) * k;
double y4 = y1 + (y2 - y1) * k;
double x5 = x2 + (x3 - x2) * k;
double y5 = y2 + (y3 - y2) * k;
double x6 = x3 + (x1 - x3) * k;
double y6 = y3 + (y1 - y3) * k;
chkmin(S, calc(x4, y4, x5, y5, x6, y6));
}
cout << fixed << setprecision(12) << S << endl;