QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#430621#8779. Square of Trianglesucup-team3215WA 362ms3764kbC++204.6kb2024-06-04 04:05:002024-06-04 04:05:01

Judging History

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

  • [2024-06-04 04:05:01]
  • 评测
  • 测评结果:WA
  • 用时:362ms
  • 内存:3764kb
  • [2024-06-04 04:05:00]
  • 提交

answer

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

using namespace std;

using fp = long double;
using P = array<fp, 2>;

__float128 sqrt(__float128 x) { return sqrt((long double)x); }
__float128 abs(__float128 x) { return x > 0? x: -x; }

P operator+(P a, P b) { return {a[0] + b[0], a[1] + b[1]}; }
P operator-(P a, P b) { return {a[0] - b[0], a[1] - b[1]}; }
P operator*(fp a, P b) { return {a * b[0], a * b[1]}; }
fp operator&(P a, P b) { return a[0] * b[0] + a[1] * b[1]; }
fp operator^(P a, P b) { return a[0] * b[1] - a[1] * b[0]; }
fp sqr(P a) { return a & a; }
fp sin(P a, P b) { return (a ^ b) / sqrt(sqr(a) * sqr(b)); }
P ccw(P a) { return {-a[1], a[0]}; }

array<P, 2> cic(P a, P b, fp ra, fp rb) {
  P v = b - a;
  fp d2 = sqr(v), sum = ra + rb, dif = ra - rb, p = (d2 + ra * ra - rb * rb) / d2 / 2, h2 = ra * ra - p * p * d2;
  P mid = a + p * v, per = sqrt(max(h2, {}) / d2) * ccw(v);
  return {mid + per, mid - per};
}

vector<P> collapse(vector<P> fig) {
  for (int i = 0; i < fig.size(); ++i) {
    int n = fig.size();
    auto a = fig[(i + n - 1) % n], b = fig[i], c = fig[(i + 1) % n];
    if (abs(sin(a - b, c - b)) < 1e-14) {
      if (abs(sqr(a - b) / sqr(c - b) - 1) > 1e-14 || (a - b & c - b) < 0) fig.erase(fig.begin() + i);
      else fig.erase(fig.begin() + i - !!i, fig.begin() + i + !i + 1);
      i = -1;
    }
  }
  return fig;
}

fp area;

bool square(vector<P> fig, vector<array<fp, 3>> tri) {
  fig = collapse(fig);
  if (fig.size() > 4 + (tri.size() == 1)) return 0;
  if (tri.empty()) return fig.size() == 4 && max({abs(sin(fig[1] - fig[0], fig[3] - fig[2])), abs(sin(fig[2] - fig[1], fig[3] - fig[0])), abs(sin(fig[2] - fig[1], fig[1] - fig[0]) + 1)}) < 1e-14 && abs((fig[2] - fig[1] ^ fig[1] - fig[0]) / area + 1) < 1e-14;
  if (fig.empty()) {
    P a{};
    P b{tri[3][0]};
    auto ntri = tri;
    ntri.erase(ntri.begin() + 3);
    if (square({a, b, cic(a, b, tri[3][1], tri[3][2])[0]}, ntri)) return 1;
    return 0;
  }
  for (int i = 0; i < tri.size(); ++i) if (!i || tri[i] != tri[i - 1])
  for (int j = 3; j--; ) if (!j || tri[i][j] != tri[i][j - 1])
  for (int k = fig.size(); k--; ) if (P a = fig[k], b = fig[(k + fig.size() - 1) % fig.size()],
      c = fig[(k + fig.size() - 2) % fig.size()], d = fig[(k + 1) % fig.size()]; abs(tri[i][j] / sqrt(sqr(a - b)) - 1) < 1e-14)
  for (int j0 = 3; j0--; ) if (int j1 = 3 - j - j0; j != j0 && j0 > j1 || tri[i][j0] != tri[i][j1]) {
    auto ntri = tri;
    ntri.erase(ntri.begin() + i);
    auto nfig = fig;
    auto np = cic(a, b, tri[i][j0], tri[i][j1])[0];
    if (sin(a - b, c - b) < 0 && sin(np - b, c - b) > 1e-14) continue;
    if (sin(b - a, d - a) > 0 && sin(np - a, d - a) > 1e-14) continue;
    nfig.insert(nfig.begin() + k, np);
    if (square(nfig, ntri)) return 1;
  }
  for (int i = 0; i < tri.size(); ++i) if (!i || tri[i] != tri[i - 1])
  for (int j = 3; j--; ) if (!j || tri[i][j] != tri[i][j - 1])
  for (int k = fig.size(); k--; ) if (P a = fig[k], b = fig[(k + fig.size() - 1) % fig.size()],
      c = fig[(k + fig.size() - 2) % fig.size()], d = fig[(k + 1) % fig.size()]; tri[i][j] / sqrt(sqr(a - b)) - 1 < -1e-14)
  for (int j0 = 3; j0--; ) if (int j1 = 3 - j - j0; j != j0 && j0 > j1 || tri[i][j0] != tri[i][j1])
  for (auto w: {0, 1}) {
    auto ntri = tri;
    ntri.erase(ntri.begin() + i);
    auto nfig = fig;
    if (w) {
      auto tp = b + tri[i][j] / sqrt(sqr(a - b)) * (a - b);
      auto np = cic(tp, b, tri[i][j0], tri[i][j1])[0];
      if (sin(a - b, c - b) < 0 && sin(np - b, c - b) > 1e-14) continue;
      if (sin(b - a, d - a) > 0 && sin(np - a, d - a) > 1e-14) continue;
      nfig.insert(nfig.begin() + k, tp);
      nfig.insert(nfig.begin() + k, np);
      if (square(nfig, ntri)) return 1;
    } else {
      auto tp = a + tri[i][j] / sqrt(sqr(a - b)) * (b - a);
      auto np = cic(a, tp, tri[i][j0], tri[i][j1])[0];
      if (sin(a - b, c - b) < 0 && sin(np - b, c - b) > 1e-14) continue;
      if (sin(b - a, d - a) > 0 && sin(np - a, d - a) > 1e-14) continue;
      nfig.insert(nfig.begin() + k, np);
      nfig.insert(nfig.begin() + k, tp);
      if (square(nfig, ntri)) return 1;
    }
  }
  return 0;
}

int main() {
  for (int tc = (cin >> tc, tc); tc--; area = 0) {
    vector<array<fp, 3>> tri(4);
    for (int i = 12, x; i--; ) cin >> x, tri[0][i] = sqrt((fp)x);
    for (auto& v: tri) {
      sort(v.begin(), v.end());
      area += abs(v[0] * cic({}, {v[0]}, v[1], v[2])[0][1]) / 2;
    }
    sort(tri.begin(), tri.end());
    cout << square({}, tri) << '\n';
  }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 5ms
memory: 3576kb

input:

3
1 1 2
2 1 1
2 1 1
1 2 1
1 1 1
1 1 1
1 1 1
1 1 1
5 125 130
125 20 145
45 130 145
145 145 80

output:

1
0
1

result:

ok 3 lines

Test #2:

score: -100
Wrong Answer
time: 362ms
memory: 3764kb

input:

20
1998001 7984010 9982009
1998001 7984010 1994005
7984010 9978013 9982009
9978013 1994005 7984010
9958045 7968034 9962037
7968034 1994005 9962037
9958045 1990013 7968034
1994005 1990013 7968034
7952074 9938097 1986025
7952074 9942085 1990013
7952074 9942085 9938097
1986025 7952074 1990013
7936130 9...

output:

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0

result:

wrong answer 1st lines differ - expected: '1', found: '0'