QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#298934#7903. Computational Intelligenceucup-team087#WA 1318ms4196kbC++143.4kb2024-01-06 16:01:572024-01-06 16:01:57

Judging History

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

  • [2024-01-06 16:01:57]
  • 评测
  • 测评结果:WA
  • 用时:1318ms
  • 内存:4196kb
  • [2024-01-06 16:01:57]
  • 提交

answer

#include <cassert>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

using Int = long long;

template <class T1, class T2> ostream &operator<<(ostream &os, const pair<T1, T2> &a) { return os << "(" << a.first << ", " << a.second << ")"; };
template <class T> ostream &operator<<(ostream &os, const vector<T> &as) { const int sz = as.size(); os << "["; for (int i = 0; i < sz; ++i) { if (i >= 256) { os << ", ..."; break; } if (i > 0) { os << ", "; } os << as[i]; } return os << "]"; }
template <class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cerr << *i << " "; cerr << endl; }
template <class T> bool chmin(T &t, const T &f) { if (t > f) { t = f; return true; } return false; }
template <class T> bool chmax(T &t, const T &f) { if (t < f) { t = f; return true; } return false; }
#define COLOR(s) ("\x1b[" s "m")


using Double = double;
constexpr Double EPS = 1e-12;
constexpr int N = 900;
static_assert(N % 2 == 0);

int main() {
  for (int numCases; ~scanf("%d", &numCases); ) { for (int caseId = 1; caseId <= numCases; ++caseId) {
    Double X[4][2];
    for (int i = 0; i < 4; ++i) for (int j = 0; j < 2; ++j) {
      int x;
      scanf("%d", &x);
      X[i][j] = x;
    }
    for (int j = 0; j < 2; ++j) X[1][j] -= X[0][j];
    for (int j = 0; j < 2; ++j) X[3][j] -= X[2][j];
    
    Double a = 0.0;
    for (int j = 0; j < 2; ++j) {
      a += X[3][j]*X[3][j];
    }
    const Double sa = sqrt(a);
    auto calc = [&](Double s) -> Double {
      Double /*a = 0.0, */b = 0.0, c = 0.0;
      for (int j = 0; j < 2; ++j) {
        // ((X[2][j] + X[3][j] t) - (X[0][j] + X[1][j] s))^2
        const Double f = X[3][j];
        const Double g = X[2][j] - (X[0][j] + X[1][j] * s);
        // a += f*f;
        b += 2*f*g;
        c += g*g;
      }
      const Double l = b / (2*a);
      const Double r = l + 1;
      // const Double sa = sqrt(a);
      const Double d = (c - b*b / (4*a)) / a;
      if (d <= EPS) {
        // auto sub = [&](Double u) -> Double {
          // return sa * u*u/2;
        // };
        if (0 <= l) {
          // return sub(r) - sub(l);
          return sa/2 * (r*r - l*l);
        } else if (r <= 0) {
          // return sub(l) - sub(r);
          return sa/2 * (l*l - r*r);
        } else {
          // return sub(l) + sub(r)/* - 2 * sub(0)*/;
          return sa/2 * (l*l + r*r);
        }
      } else {
        // auto sub = [&](Double u) -> Double {
          // const Double su = sqrt(u*u + d);
          // return sa * (u * su - d * log(su - u)) / 2;
        // };
        // return sub(r) - sub(l);
        const Double sl = sqrt(l*l + d);
        const Double sr = sqrt(r*r + d);
        return sa/2 * ((r*sr - l*sl) - d * log((sr - r) / (sl - l)));
      }
    };
    
    Double ans = 0.0;
    for (int i = 0; i <= N; ++i) {
      const Double res = calc(1.0 / N * i);
      ans += ((i == 0 || i == N) ? 1 : (i % 2 == 0) ? 2 : 4) * res;
    }
    ans /= N;
    ans /= 3;
    printf("%.12f\n", ans);
  }
#ifndef LOCAL
  break;
#endif
  }
  return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 4196kb

input:

3
0 0 1 0
0 0 1 0
0 0 1 0
0 0 0 1
0 0 1 0
0 1 1 1

output:

0.333333333333
0.765195716492
1.076635732895

result:

ok 3 numbers

Test #2:

score: 0
Accepted
time: 1ms
memory: 4152kb

input:

3
0 1 0 0
0 -1 0 2
0 0 1 0
2 0 -1 0
-1000 0 0 999
0 -998 999 0

output:

0.777777777778
0.777777777778
1521.070405024651

result:

ok 3 numbers

Test #3:

score: -100
Wrong Answer
time: 1318ms
memory: 4076kb

input:

100000
-4 -10 -8 -8
5 5 -10 -8
-10 10 -1 -3
-3 5 -1 -3
8 -7 8 -10
0 -3 0 10
6 -1 0 2
0 -3 3 1
-6 -5 5 3
3 5 -4 -8
1 9 1 -1
2 -1 -6 0
1 -2 -7 -9
-1 -2 -4 5
6 -10 7 1
0 -6 -8 -8
-10 9 2 3
-7 -10 4 -9
8 4 4 9
-9 3 0 4
5 -2 9 8
-9 -5 7 8
-1 1 0 1
-4 1 -8 1
3 3 10 3
3 0 -6 -2
-3 -3 -3 3
-2 7 -10 -7
9 2 6...

output:

9.028267617368
5.744131449001
14.594278702892
2.952178243305
4.993502694409
6.058717253904
7.459408700248
11.228028907920
16.325707847495
11.072245157190
9.504557451156
5.500000000000
9.040049985829
5.326347910887
3.035934371290
5.808804180103
17.363719789522
9.995194519237
6.993302622881
6.55043322...

result:

wrong answer 137th numbers differ - expected: '6.4478215', found: '6.4478214', error = '0.0000000'