QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#533164#7521. Find the GaplongyinWA 0ms3920kbC++142.2kb2024-08-25 17:59:582024-08-25 17:59:58

Judging History

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

  • [2024-08-25 17:59:58]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3920kb
  • [2024-08-25 17:59:58]
  • 提交

answer

#include <bits/stdc++.h>
#define endl "\n"
using namespace std;

using ll = long long;
const double INF = 1e9;
const int N = 55;

struct Point {
    ll x, y, z;
} points[N];

struct Vector {
    ll x, y, z;
};

struct Plane {
    ll a, b, c, d;
};

ll toLeftTest(Point p, Point q, Point s) {
    return p.x * q.y + q.x * s.y + s.x * p.y - p.x * s.y - q.x * p.y - s.x * q.y;
}

Plane crossProduct(const Vector& p1, const Vector& p2, const Point& p) {
    Plane res;
    res.a = p1.y * p2.z - p1.z * p2.y;
    res.b = p1.z * p2.x - p1.x * p2.z;
    res.c = p1.x * p2.y - p1.y * p2.x;
    res.d = -(res.a * p.x + res.b * p.y + res.c * p.z);
    return res;
}

double distance(Point& p, Plane& pla) {
    return (1.0 * pla.a * p.x + pla.b * p.y + pla.c * p.z + pla.d) / sqrt(pla.a * pla.a + pla.b * pla.b + pla.c * pla.c);
}

int main() {
    ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);

    int n;
    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> points[i].x >> points[i].y >> points[i].z;
    }

    if (n <= 3) {
        cout << 0 << endl;
        return 0;
    }

    double ans = INF;
    for (int i = 1; i <= n; i++) {
        Point p = points[i];
        for (int j = i + 1; j <= n; j++) {
            Point q = points[j];
            for (int k = j + 1; k <= n; k++) {
                Point s = points[k];
                if (toLeftTest(p, q, s) == 0) 
                    continue;
                Vector p1 = {p.x - q.x, p.y - q.y, p.z - q.z};
                Vector p2 = {s.x - q.x, s.y - q.y, s.z - q.z};
                Plane pla = crossProduct(p1, p2, q);

                int cnt1 = 0, cnt2 = 0;
                double cur = 0;
                for (int l = 1; l <= n; l++) {
                    double d = distance(points[l], pla);
                    if (d > 0)
                        cnt1++;
                    if (d < 0)
                        cnt2++;
                    cur = max(cur, abs(d));
                }
                if (!(cnt1 && cnt2)) {
                    ans = min(ans, cur);
                }
            }
        }
    }

    cout << fixed << setprecision(20) << ans << endl;

    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

8
1 1 1
1 1 2
1 2 1
1 2 2
2 1 1
2 1 2
2 2 1
2 2 2

output:

1.00000000000000000000

result:

ok found '1.000000000', expected '1.000000000', error '0.000000000'

Test #2:

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

input:

5
1 1 1
1 2 1
1 1 2
1 2 2
2 1 1

output:

0.70710678118654746172

result:

ok found '0.707106781', expected '0.707106781', error '0.000000000'

Test #3:

score: -100
Wrong Answer
time: 0ms
memory: 3884kb

input:

50
973 1799 4431
1036 1888 4509
1099 1977 4587
1162 2066 4665
1225 2155 4743
1288 2244 4821
1351 2333 4899
1414 2422 4977
1540 2600 5133
1603 2689 5211
1666 2778 5289
1729 2867 5367
1792 2956 5445
1855 3045 5523
1918 3134 5601
1981 3223 5679
2044 3312 5757
2107 3401 5835
2170 3490 5913
2296 3668 606...

output:

1000000000.00000000000000000000

result:

wrong answer 1st numbers differ - expected: '0.0000000', found: '1000000000.0000000', error = '1000000000.0000000'