QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#371249#8505. Almost Aligneducup-team3215Compile Error//C++201.7kb2024-03-30 03:19:502024-03-30 03:19:51

Judging History

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

  • [2024-03-30 03:19:51]
  • 评测
  • [2024-03-30 03:19:50]
  • 提交

answer

#include <algorithm>
#include <array>
#include <cmath>
#include <cstdint>
#include <iostream>
#include <vector>

using namespace std;

using point = array<int, 2>;

int64_t operator^(point a, point b) { return a[0] * (int64_t)b[1] - a[1] * (int64_t)b[0]; }
int64_t operator&(point a, point b) { return a[0] * (int64_t)b[0] + a[1] * (int64_t)b[1]; }
point operator-(point a) { return {-a[0], -a[1]}; }
point operator-(point a, point b) { return {a[0] - b[0], a[1] - b[1]}; }

vector<point> env(const vector<point>& v) {
  vector<point> e;
  for (auto& p: v) {
    while (e.size() > 1 && (e.back() - e.end()[-2] ^ p - e.back()) >= 0) e.pop_back();
    e.push_back(p);
  }
  return e;
}

int main() {
  cin.tie(0)->sync_with_stdio(0);
  int n; cin >> n;
  vector<point> v[2];
  v[0].resize(n), v[1].resize(n);
  for (int i = 0; i < n; ++i) cin >> v[0][i][1] >> v[1][i][1] >> v[0][i][0] >> v[1][i][0];
  vector<point> e[4];
  for (int c: {0, 1}) {
    sort(v[c].begin(), v[c].end());
    e[c * 2] = env(v[c]);
    for (auto& p: v[c]) p = -p;
    reverse(v[c].begin(), v[c].end());
    e[c * 2 + 1] = env(v[c]);
  }
  auto ans = 0.L / 0;
  int i[4]{};
  while (1) {
    int w = -1;
    for (int j = 0; j < 4; ++j) if (i[j] + 1 < e[j].size() && (!~w || (e[j][i[j] + 1] - e[j][i[j]] ^ e[w][i[w] + 1] - e[w][i[w]]) < 0)) w = j;
    point a = e[0][i[0]] - -e[1][i[1]], b = e[2][i[2]] - -e[3][i[3]], d;
    if (~w) d = e[w][i[w] + 1] - e[w][i[w]], ++i[w];
    if ((!~w || d[1] < 0) && isnan(ans)) ans = a[1] * 1.L * b[1];
    if (!~w) break;
    if (d[1] < 0) ans = min(ans, (d ^ a) * 1.L * (d ^ b) / d[0] / d[0]);
  }
  assert(isfinite(ans) && ans >= 0);
  cout.precision(20);
  cout << fixed << ans;
}

Details

answer.code: In function ‘int main()’:
answer.code:40:18: warning: division by zero [-Wdiv-by-zero]
   40 |   auto ans = 0.L / 0;
      |              ~~~~^~~
answer.code:51:3: error: ‘assert’ was not declared in this scope
   51 |   assert(isfinite(ans) && ans >= 0);
      |   ^~~~~~
answer.code:7:1: note: ‘assert’ is defined in header ‘<cassert>’; did you forget to ‘#include <cassert>’?
    6 | #include <vector>
  +++ |+#include <cassert>
    7 |