QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#226876#7521. Find the GapJayintCompile Error//C++142.8kb2023-10-26 17:36:052023-10-26 17:36:07

Judging History

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

  • [2023-10-26 17:36:07]
  • 评测
  • [2023-10-26 17:36:05]
  • 提交

answer

作者:CurryWOE
链接:https://zhuanlan.zhihu.com/p/659497901
来源:知乎
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。

#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));
    }
}a[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 >> a[i].x >> a[i].y >> a[i].z;
    for (int i = 0; i < n; ++i)
        for (int j = i + 1; j < n; ++j)
            if (a[i] != a[j])
                line.push_back(a[i]-a[j]);
    double ans = INF;
    for (int i = 0; i < line.size(); ++i)
    {
        point3 A = line[i];
        for (int j = i + 1; j < line.size(); ++j)
        {
            point3 B = line[j];
            if (zero(fabs(dmult(A, B)/vlen(A)/vlen(B))-1))
                continue;
            point3 normalVector = xmult(A, B);
            normalVector=normalVector/vlen(normalVector);
            point3 mi = {INF, INF, INF}, ma = {-INF, -INF, -INF};
            for (int k = 0; k < n; ++k)
            {
                point3 res = projection(a[k], normalVector);
                if (res < mi)
                    mi = res;
                if (ma < res)
                    ma = res;
            }
            ans = min(ans, vlen(mi-ma));
        }
    }
    if (ans == INF || zero(ans))
        ans = 0;
    cout << fixed << setprecision(15) << ans;
    return 0;
}

Details

answer.code:4:1: error: extended character 。 is not valid in an identifier
    4 | 著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。
      | ^
answer.code:4:1: error: extended character 。 is not valid in an identifier
answer.code:1:1: error: ‘作者:CurryWOE’ does not name a type
    1 | 作者:CurryWOE
      | ^~~~~~~~~~~~~~
In file included from /usr/include/c++/11/iosfwd:40,
                 from /usr/include/c++/11/ios:38,
                 from /usr/include/c++/11/ostream:38,
                 from /usr/include/c++/11/iostream:39,
                 from answer.code:6:
/usr/include/c++/11/bits/postypes.h:98:11: error: ‘ptrdiff_t’ does not name a type
   98 |   typedef ptrdiff_t     streamsize; // Signed integral type
      |           ^~~~~~~~~
/usr/include/c++/11/bits/postypes.h:41:1: note: ‘ptrdiff_t’ is defined in header ‘<cstddef>’; did you forget to ‘#include <cstddef>’?
   40 | #include <cwchar> // For mbstate_t
  +++ |+#include <cstddef>
   41 | 
In file included from /usr/include/c++/11/bits/exception_ptr.h:40,
                 from /usr/include/c++/11/exception:147,
                 from /usr/include/c++/11/ios:39,
                 from /usr/include/c++/11/ostream:38,
                 from /usr/include/c++/11/iostream:39,
                 from answer.code:6:
/usr/include/c++/11/new:126:26: error: declaration of ‘operator new’ as non-function
  126 | _GLIBCXX_NODISCARD void* operator new(std::size_t) _GLIBCXX_THROW (std::bad_alloc)
      |                          ^~~~~~~~
/usr/include/c++/11/new:126:44: error: ‘size_t’ is not a member of ‘std’; did you mean ‘size_t’?
  126 | _GLIBCXX_NODISCARD void* operator new(std::size_t) _GLIBCXX_THROW (std::bad_alloc)
      |                                            ^~~~~~
In file included from /usr/include/wchar.h:35,
                 from /usr/include/c++/11/cwchar:44,
                 from /usr/include/c++/11/bits/postypes.h:40,
                 from /usr/include/c++/11/iosfwd:40,
                 from /usr/include/c++/11/ios:38,
                 from /usr/include/c++/11/ostream:38,
                 from /usr/include/c++/11/iostream:39,
                 from answer.code:6:
/usr/lib/gcc/x86_64-linux-gnu/11/include/stddef.h:209:23: note: ‘size_t’ declared here
  209 | typedef __SIZE_TYPE__ size_t;
      |                       ^~~~~~
In file included from /usr/include/c++/11/bits/exception_ptr.h:40,
                 from /usr/include/c++/11/exception:147,
                 from /usr/include/c++/11/ios:39,
                 from /usr/include/c++/11/ostream:38,
                 from /usr/include/c++/11/iostream:39,
                 from answer.code:6:
/usr/include/c++/11/new:127:41: error: attributes after parenthesized initializer ignored [-fpermissive]
  127 |   __attribute__((__externally_visible__));
      |                                         ^
/usr/include/c++/11/new:128:26: error: declaration of ‘operator new []’ as non-function
  128 | _GLIBCXX_NODISCARD void* operator new[](std::size_t) _GLIBCXX_THROW (std::bad_alloc)
      |                          ^~~~~~~~
/usr/include/c++/11/new:128:46: error: ‘size_t’ is not a member of ‘std’; did you mean ‘size_t’?
  128 | _GLIBCXX_NODISCARD void* operator new[](std::size_t) _GLIBCXX_THROW (std::bad_alloc)
      |                                              ^~~~~~
In file included from /usr/include/wchar.h:35,
                 from /usr/include/c++/11/cwchar:44,
                 from /usr/include/c++/11/bits/postypes.h:40,
                 from /usr/include/c++/11/iosfwd:40,
                 from /usr/include/c++/11/ios:38,
                 from /usr/include/c++/11/ostream:38,
                 from /usr/include/c++/11/iostream:39,
                 from answer.code:6:
/usr/lib/gcc/x86_64-linux-gnu/11/include/stddef.h:209:23: note: ‘size_t’ declared here
  209 | typedef __SIZE_TYPE__ size_t;
      |                       ^~~~~~
In file included from /usr/include/c++/11/bits/exception_ptr.h:40,
                 from /usr/include/c++/11/exception:147,
                 from /usr/include/c++/11/ios:39,
                 from /usr/include/c++/11/ostream:38,
                 from /usr/include/c++/11/iostream:39,
                 from answer.code:6:
/usr/include/c++/11/new:129:41: error: attributes after parenthesized initializer ignored [-fpermissive]
  129 |   __attribute__((__externally_visible__));
      |                                         ^
/usr/include/c++/11/new:135:34: error: ‘std::size_t’ has not been declared
  135 | void operator delete(void*, std::size_t) _GLIBCXX_USE_NOEXCEPT
      |                                  ^~~~~~
/usr/include/c++/11/new:137:36: error: ‘std::size_t’ has not been declared
  137 | void operator delete[](void*, std::size_t) _GLIBCXX_USE_NOEXCEPT
      |                                    ^~~~~~
/usr/include/c++/11/new:140:26: error: declaration of ‘operator new’ as non-function
  140 | _GLIBCXX_NODISCARD void* operator new(std::size_t, const std::nothrow_t&) _GLIBCXX_USE_NOEXCEPT
      |           ...