QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#226884#7521. Find the GapJayintWA 0ms3828kbC++142.3kb2023-10-26 17:42:522023-10-26 17:42:53

Judging History

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

  • [2023-10-26 17:42:53]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3828kb
  • [2023-10-26 17:42:52]
  • 提交

answer

#include <iostream>
#include<cmath>
#include<vector>
#include<iomanip>
using namespace std;
const int N = 53;
const double INF = 1e18;
const double eps = 1e-8;
#define zero(x) (((x) > 0 ? (x) : -(x)) < eps)
struct point3
{
    double x, y, z;
    point3 operator+(const point3 &o) const
    {
        return {x + o.x, y + o.y, z + o.z};
    }
    point3 operator-(const point3 &o) const
    {
        return {x - o.x, y - o.y, z - o.z};
    }
    point3 operator*(const double &o) const
    {
        return {x * o , y * o, z * o};
    }
    point3 operator/(const double &o) const
    {
        return {x / o , y / o, z / o};
    }
    bool operator<(const point3 &o) const
    {
        if (!zero(x - o.x))
            return x < o.x;
        if (!zero(y - o.y))
            return y < o.y;
        return z < o.z;
    }
    bool operator!=(const point3 &o) const
    {
        return (!zero(x - o.x) || !zero(y - o.y) || !zero(z - o.z));
    }
} p[N];
vector<point3> line;
double vlen(point3 p)
{
    return sqrt(p.x * p.x + p.y * p.y + p.z * p.z);
}
point3 xmult(point3 u, point3 v)
{
    point3 ret;
    ret.x = u.y * v.z - v.y * u.z;
    ret.y = u.z * v.x - u.x * v.z;
    ret.z = u.x * v.y - u.y * v.x;
    return ret;
}
double dmult(point3 u, point3 v)
{
    return u.x * v.x + u.y * v.y + u.z * v.z;
}
point3 projection(point3 p, point3 u)
{
    return u * dmult(p, u);
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int n;
    cin >> n;
    for (int i = 0; i < n; ++i)
        cin >> p[i].x >> p[i].y >> p[i].z;
    if (n <= 3) {
        cout << 0 << '\n';
        return 0;
    }
    double ans = 1e18;
    for (int i = 0; i < n; i++) {
        for (int j = i + 1; j < n; j++) {
            for (int k = j + 1; k < n; k++) {
                point3 v1 = xmult(p[j] - p[i], p[k] - p[i]);
                double maxn = -1e18;
                double minn = 1e18;
                for (int l = 0; l < n; l++) {
                    double k = dmult(v1, p[l]) / vlen(v1);
                    maxn = max(maxn, k);
                    minn = min(minn, k);
                }
                ans = min(ans, maxn - minn);
            }
        }
    }
    printf("%.10f\n", ans);
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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.0000000000

result:

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

Test #2:

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

input:

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

output:

0.7071067812

result:

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

Test #3:

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

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:

-nan

result:

wrong output format Expected double, but "-nan" found