论数据
查看原帖
论数据
904032
_colin1112_楼主2024/5/5 11:49

暴力求p竟然能过。

#include <bits/stdc++.h>
#define endl '\n'
#define ll long long

using namespace std;
const int E = 1e6 + 5;
long double x_1, y_1, x_2, y_2, x_3, y_3, l, r, ans = 1e18;
inline long double dis(long double p, long double q, long double p1, long double q1)
{
    return sqrt((p - p1) * (p - p1) + (q - q1) * (q - q1));
}
inline long double S(long double p, long double a, long double b, long double c)
{
    return sqrt(p * (p - a) * (p - b) * (p - c));
}
int main()
{
    cin >> l >> r >> x_1 >> y_1 >> x_2 >> y_2 >> x_3 >> y_3;
    for (long double i = l; i <= r; i += 0.00001)
    {
        long double x_f = x_1 - i * (x_1 - x_2);
        long double y_f = y_1 - i * (y_1 - y_2);
        long double x_d = x_2 - i * (x_2 - x_3);
        long double y_d = y_2 - i * (y_2 - y_3);
        long double x_e = x_3 - i * (x_3 - x_1);
        long double y_e = y_3 - i * (y_3 - y_1);
        long double P = (dis(x_f, y_f, x_d, y_d) + dis(x_d, y_d, x_e, y_e) + dis(x_e, y_e, x_f, y_f)) / 2;
        long double a = dis(x_f, y_f, x_d, y_d), b = dis(x_d, y_d, x_e, y_e), c = dis(x_e, y_e, x_f, y_f);
        ans = min(ans, S(P, a, b, c));
    }
    cout << fixed << setprecision(9) << ans;
    return 0;
}
2024/5/5 11:49
加载中...