QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#533167 | #7521. Find the Gap | longyin | WA | 6ms | 3916kb | C++14 | 2.2kb | 2024-08-25 18:01:04 | 2024-08-25 18:01:04 |
Judging History
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 == INF ? 0 : ans) << endl;
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3916kb
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: 3796kb
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: 0
Accepted
time: 0ms
memory: 3732kb
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:
0.00000000000000000000
result:
ok found '0.000000000', expected '0.000000000', error '-0.000000000'
Test #4:
score: 0
Accepted
time: 0ms
memory: 3912kb
input:
50 4532 3245 1339 4624 3260 1345 4716 3275 1351 4808 3290 1357 4900 3305 1363 5084 3335 1375 5176 3350 1381 5268 3365 1387 5360 3380 1393 5452 3395 1399 5544 3410 1405 5728 3440 1417 5820 3455 1423 5912 3470 1429 6096 3500 1441 6188 3515 1447 6280 3530 1453 6372 3545 1459 6464 3560 1465 6556 3575 14...
output:
0.00000000000000000000
result:
ok found '0.000000000', expected '0.000000000', error '-0.000000000'
Test #5:
score: 0
Accepted
time: 4ms
memory: 3880kb
input:
50 1 70 7443 1 138 5063 2 109 5971 3 23 8874 3 152 4359 4 59 7507 5 50 7715 5 73 6910 7 25 8376 7 103 5646 8 3 9039 9 83 6132 9 142 4067 10 124 4590 11 140 3923 12 168 2836 13 46 6999 13 84 5669 13 189 1994 13 229 594 15 171 2410 16 94 4998 20 38 6530 20 125 3485 21 78 5023 22 210 296 23 117 3444 25...
output:
0.00000000000000000000
result:
ok found '0.000000000', expected '0.000000000', error '-0.000000000'
Test #6:
score: 0
Accepted
time: 4ms
memory: 3916kb
input:
50 1 95 5991 3 22 9019 25 103 5199 25 141 3603 38 103 4952 39 139 3421 59 6 8627 60 48 6844 66 33 7360 107 88 4271 109 188 33 112 177 438 114 107 3340 122 77 4448 123 169 565 127 1 7545 142 161 540 143 70 4343 146 153 800 156 129 1618 162 63 4276 162 150 622 166 93 2940 173 78 3437 180 143 574 189 1...
output:
0.00000000000000000000
result:
ok found '0.000000000', expected '0.000000000', error '-0.000000000'
Test #7:
score: -100
Wrong Answer
time: 6ms
memory: 3740kb
input:
50 14 3658 1218 17 32 7984 741 1906 5773 755 8668 1019 834 2386 4591 1306 3866 7044 2304 2895 120 2450 8613 7374 2595 1919 2119 2610 9866 9419 2694 2845 2941 2838 2702 7608 2883 4143 4049 3082 4800 3611 3338 6703 9039 3424 2035 1863 3471 2672 5858 4339 1330 2029 4720 6970 4719 4853 387 5866 5415 975...
output:
9414.05796416416342253797
result:
wrong answer 1st numbers differ - expected: '9341.5658962', found: '9414.0579642', error = '0.0077602'