QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#797861#3594. Weird Flecks, But OKLaVuna47#TL 0ms3924kbC++204.2kb2024-12-03 19:54:582024-12-03 19:54:58

Judging History

你现在查看的是最新测评结果

  • [2024-12-03 19:54:58]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:3924kb
  • [2024-12-03 19:54:58]
  • 提交

answer

/** gnu specific **/
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
/** contains everything I need in std **/
#include <bits/stdc++.h>

#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(S) ((int)S.size())
#define FOR(i, st_, n) for(int i = st_; i < n; ++i)
#define RFOR(i, n, end_) for(int i = (n)-1; i >= end_; --i)
#define x first
#define y second
#define pb push_back
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef unsigned long long ull;
typedef long double LD;
typedef pair<ull, ull> pull;
using namespace __gnu_pbds;
typedef tree<ll, null_type, less<>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
using namespace std;
#ifdef ONPC
mt19937 rnd(228);
#else
mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());
#endif


struct Point {
    double x, y;
};

double dist(const Point& a, const Point& b) {
    return sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y));
}

struct Circle {
    Point center;
    double radius;
};

Circle make_circle_two_points(const Point& p1, const Point& p2) {
    Point center = {(p1.x + p2.x) / 2.0, (p1.y + p2.y) / 2.0};
    double radius = dist(p1, center);
    return {center, radius};
}

Circle make_circle_three_points(const Point& p1, const Point& p2, const Point& p3) {
    double A = p2.x - p1.x, B = p2.y - p1.y;
    double C = p3.x - p1.x, D = p3.y - p1.y;
    double E = A * (p1.x + p2.x) + B * (p1.y + p2.y);
    double F = C * (p1.x + p3.x) + D * (p1.y + p3.y);
    double G = 2 * (A * (p3.y - p2.y) - B * (p3.x - p2.x));

    if (fabs(G) < 1e-9) return {{0, 0}, numeric_limits<double>::max()}; // Collinear points

    Point center = {(D * E - B * F) / G, (A * F - C * E) / G};
    double radius = dist(center, p1);
    return {center, radius};
}

bool is_inside(const Circle& c, const Point& p) {
    return dist(c.center, p) <= c.radius + 1e-9;
}

Circle min_enclosing_circle(vector<Point>& points) {
    int n = points.size();
    Circle min_circle = {{0, 0}, numeric_limits<double>::max()};

    for (int i = 0; i < n; ++i)
    {
        for (int j = i + 1; j < n; ++j)
        {
            Circle c = make_circle_two_points(points[i], points[j]);
            if(c.radius >= min_circle.radius)
				continue;
            bool valid = true;
            for (const Point& p : points) {
                if (!is_inside(c, p)) {
                    valid = false;
                    break;
                }
            }
            if (valid && c.radius < min_circle.radius) {
                min_circle = c;
            }

            for (int k = j + 1; k < n; ++k) {
                Circle c3 = make_circle_three_points(points[i], points[j], points[k]);
                valid = true;
                for (const Point& p : points) {
                    if (!is_inside(c3, p)) {
                        valid = false;
                        break;
                    }
                }
                if (valid && c3.radius < min_circle.radius) {
                    min_circle = c3;
                }
            }
        }
    }

    return min_circle;
}

int solve()
{
	int n;
	if(!(cin>>n))return 1;
	vector<array<double,3>> A(n);
	FOR(i,0,n)FOR(j,0,3)cin>>A[i][j];
	shuffle(all(A),rnd);
    vector<Point> p1(n), p2(n), p3(n);
    FOR(i,0,n)p1[i]={A[i][0],A[i][1]};
    FOR(i,0,n)p2[i]={A[i][0],A[i][2]};
    FOR(i,0,n)p3[i]={A[i][1],A[i][2]};
    

    Circle c1 = min_enclosing_circle(p1);
    Circle c2 = min_enclosing_circle(p2);
    Circle c3 = min_enclosing_circle(p3);
	double res =min(c1.radius,min(c2.radius,c3.radius));
	cout << fixed << setprecision(10) << 2*res << '\n';
    return 0;
}

int32_t main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int TET = 1e9;
    //cin >> TET;
    for (int i = 1; i <= TET; i++)
    {
        if (solve())
        {
            break;
        }
#ifdef ONPC
        cout << "__________________________" << endl;
#endif
    }
#ifdef ONPC
    cerr << endl << "finished in " << clock() * 1.0 / CLOCKS_PER_SEC << " sec" << endl;
#endif
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3904kb

input:

3
1.0 0.0 1.4
-1.0 0.0 -1.4
0.0 1.0 -0.2

output:

2.0000000000

result:

ok found '2.00000', expected '2.00000', error '0.00000'

Test #2:

score: 0
Accepted
time: 0ms
memory: 3924kb

input:

5
1.4 1.0 0.0
-0.4 -1.0 0.0
-0.1 -0.25 -0.5
-1.2 0.0 0.9
0.2 0.5 0.5

output:

2.0000000000

result:

ok found '2.00000', expected '2.00000', error '0.00000'

Test #3:

score: 0
Accepted
time: 0ms
memory: 3912kb

input:

8
435.249 -494.71 -539.356
455.823 -507.454 -539.257
423.394 -520.682 -538.858
446.507 -501.953 -539.37
434.266 -503.664 -560.631
445.059 -549.71 -537.501
449.65 -506.637 -513.778
456.05 -499.715 -561.329

output:

49.9998293198

result:

ok found '49.99983', expected '49.99983', error '0.00000'

Test #4:

score: -100
Time Limit Exceeded

input:

1000
316.667 322.677 -304.77
315.164 324.611 -306.964
314.498 323.169 -305.335
316.351 324.314 -303.093
316.459 323.113 -308.607
315.298 323.223 -308.678
314.523 324.616 -304.568
315.904 322.836 -304.76
316.635 324.611 -305.856
318.017 324.31 -305.868
315.815 324.613 -306.005
316.247 324.591 -305.62...

output:


result: