QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#565169#9316. BoxesAfterlifeCompile Error//C++172.5kb2024-09-15 20:29:302024-09-15 20:29:31

Judging History

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

  • [2024-09-15 20:29:31]
  • 评测
  • [2024-09-15 20:29:30]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
using db = __int128;
using T = db;
struct P {
  T x, y, z;
  explicit P(T x = 0, T y = 0, T z = 0) : x(x), y(y), z(z) {}
  T dot(P p) { return x * p.x + y * p.y + z * p.z; }
  P cross(P p) { return P(y * p.z - z * p.y, z * p.x - x * p.z, x * p.y - y * p.x); }
  P operator-(P p) { return P(x - p.x, y - p.y, z - p.z); }
  db length() { return sqrt(x * x + y * y + z * z); }
//   friend ostream& operator<<(ostream& os, P p) { return os << "(" << p.x << ", " << p.y << ", " << p.z << ")"; }
};
const int L = 1e5;
vector<tuple<int, int, int>> hull(vector<P> p, T eps = 1e-9) {
  mt19937 mt(random_device{}());
  int d = mt() % L;
  for (auto& [x, y, z] : p) {
    x += d;
    y += d;
    z += d;
  }
  vector<tuple<int, int, int>> res;
  if(p.size() < 3)
    return res;
  res.emplace_back(0, 1, 2);
  res.emplace_back(0, 2, 1);
  for (int i = 3; i < p.size(); i += 1) {
    vector<tuple<int, int, int>> nxt;
    set<pair<int, int>> edge;
    for (auto [a, b, c] : res) {
      T prod = (p[b] - p[a]).cross(p[c] - p[a]).dot(p[i] - p[a]);
      if (prod > 0) {
        edge.emplace(a, b);
        edge.emplace(b, c);
        edge.emplace(c, a);
      } else
        nxt.emplace_back(a, b, c);
    }
    for (auto [x, y] : edge) {
      if (edge.find({y, x})!=edge.end()) continue;
      nxt.emplace_back(x, y, i);
    }
    res.swap(nxt);
  }
  return res;
}
db volume(vector<P> p, vector<tuple<int, int, int>> f) {
  db res = 0;
  for (auto [a, b, c] : f) res += p[a].cross(p[b]).dot(p[c]);
  return  res;
}
db area(vector<P> p, vector<tuple<int, int, int>> f) {
  db res = 0;
  for (auto [a, b, c] : f) res += (p[b] - p[a]).cross(p[c] - p[b]).length();
  return res / 2;
}

int main() {
    int T;
    cin >> T;
    while(T--) {
        int n;
        cin >> n;
        vector<P> v(n);
        for(auto &[x, y, z] : v) {
            long long a, b, c;
            cin >> a >> b >> c;
            x = a, y = b, z = c;
            // cin >> x >> y >> z;
        }
        db ans = 0;
        while(v.size() > 3) {
            auto h = hull(v);
            ans += volume(v, h);
            vector<int> use(v.size());
            for(auto [x, y, z] : h)
                use[x] = use[y] = use[z] = 1;
            vector<P> nv;
            for(int i = 0; i < v.size(); i += 1)
                if(!use[i])
                    nv.push_back(v[i]);
            v.swap(nv);
        }
        cout << (long long)(ans) << "\n";
    }
}

詳細信息

answer.code: In member function ‘db P::length()’:
answer.code:11:28: error: call of overloaded ‘sqrt(T)’ is ambiguous
   11 |   db length() { return sqrt(x * x + y * y + z * z); }
      |                        ~~~~^~~~~~~~~~~~~~~~~~~~~~~
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)
      |   ^~~~