QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#533177#7521. Find the GaplongyinCompile Error//C++142.2kb2024-08-25 18:09:322024-08-25 18:09:32

Judging History

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

  • [2024-08-25 18:09:32]
  • 评测
  • [2024-08-25 18:09:32]
  • 提交

answer

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

//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++) {
        int x, y, z;
        cin >> x >> y >> z;
        points[i] = {x, y, 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

answer.code: In function ‘double distance(Point&, Plane&)’:
answer.code:36:74: error: call of overloaded ‘sqrt(__int128)’ is ambiguous
   36 |     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);
      |                                                                      ~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/features.h:461,
                 from /usr/include/x86_64-linux-gnu/c++/13/bits/os_defines.h:39,
                 from /usr/include/x86_64-linux-gnu/c++/13/bits/c++config.h:679,
                 from /usr/include/c++/13/cassert:43,
                 from /usr/include/x86_64-linux-gnu/c++/13/bits/stdc++.h:33,
                 from answer.code:1:
/usr/include/x86_64-linux-gnu/bits/mathcalls.h:143:1: note: candidate: ‘double sqrt(double)’
  143 | __MATHCALL (sqrt,, (_Mdouble_ __x));
      | ^~~~~~~~~~
In file included from /usr/include/x86_64-linux-gnu/c++/13/bits/stdc++.h:114:
/usr/include/c++/13/cmath:442:3: note: candidate: ‘constexpr long double std::sqrt(long double)’
  442 |   sqrt(long double __x)
      |   ^~~~
/usr/include/c++/13/cmath:438:3: note: candidate: ‘constexpr float std::sqrt(float)’
  438 |   sqrt(float __x)
      |   ^~~~