60pts 求调
查看原帖
60pts 求调
672333
VitrelosTia楼主2024/5/4 19:38
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

struct Line {
	long double a, b, c; // ax + by + c = 0
} ab, ac, bc;
Line getLine(long double x1, long double y1, long double x2, long double y2) {
	long double a = y2 - y1;
	long double b = x1 - x2;
	long double c = x2 * y1 - x1 * y2;
	return {a, b, c};
};
long double getx(Line l, long double y) { return (-l.b * y - l.c) / l.a; }
long double q(long double x) { return x * x; }
long double dis(long double x1, long double x2, long double y1, long double y2) { return sqrt(q(x1 - x2) + q(y1 - y2)); }
long double calc(long double a, long double b, long double c) { long double p = (a + b + c) / 2.0; return sqrt(p * (p - a) * (p - b) * (p - c)); }
// void check(long double x, long double y) { printf ("x = %.10lf, y = %.10lf\n", x, y); }

int main() {
//	ios::sync_with_stdio(false); cin.tie(nullptr);
	long double l, r, x1, y1, x2, y2, x3, y3;
	cin >> l >> r >> x1 >> y1 >> x2 >> y2 >> x3 >> y3;
	ab = getLine(x1, y1, x2, y2); bc = getLine(x2, y2, x3, y3); ac = getLine(x1, y1, x3, y3);
	long double ans = 1e18;
	for (long double p = l - 0.00001; p <= r + 0.00001; p += 0.00001) {
		long double dy = (y3 + y2) * (y2 < y3 ? p : (1.0 - p)); long double dx = bc.a == 0 ? (x3 + x2) * (x2 < x3 ? p : (1.0 - p)) : getx(bc, dy);
		long double ey = (y1 + y3) * (y3 < y1 ? p : (1.0 - p)); long double ex = ac.a == 0 ? (x1 + x3) * (x3 < x1 ? p : (1.0 - p)) : getx(ac, ey);
		long double fy = (y2 + y1) * (y1 < y2 ? p : (1.0 - p)); long double fx = ab.a == 0 ? (x2 + x1) * (x1 < x2 ? p : (1.0 - p)) : getx(ab, fy);
//		check(dx, dy); check(ex, ey); check(fx, fy);
		long double de = dis(dx, ex, dy, ey);
		long double ef = dis(ex, fx, ey, fy);
		long double df = dis(dx, fx, dy, fy);
		long double S = calc(de, ef, df);
//		printf ("p = %.10lf, S = %.10lf\n", p, S);
		ans = min(ans, S);
	}
	cout << setprecision(10) << fixed << ans;
	return 0;
}
2024/5/4 19:38
加载中...