QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#298855#7903. Computational Intelligenceucup-team087#WA 1ms4140kbC++143.0kb2024-01-06 15:13:062024-01-06 15:13:07

Judging History

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

  • [2024-01-06 15:13:07]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:4140kb
  • [2024-01-06 15:13:06]
  • 提交

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 = 800;
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];
    
    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 = b / (2*a) + 1;
      const Double d = (c - b*b / (4*a)) / a;
      if (d <= EPS) {
        auto sub = [&](Double u) -> Double {
          return a * u*u/2;
        };
        if (0 <= l) {
          return sub(r) - sub(l);
        } else if (r <= 0) {
          return sub(l) - sub(r);
        } else {
          return sub(l) + sub(r)/* - 2 * sub(0)*/;
        }
      } else {
        auto sub = [&](Double u) -> Double {
          const Double su = sqrt(u*u + d);
          return a * (u * su - d * log(su - u)) / 2;
        };
        return sub(r) - sub(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;
}

详细

Test #1:

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

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.765195716504
1.076635732895

result:

ok 3 numbers

Test #2:

score: -100
Wrong Answer
time: 0ms
memory: 4120kb

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:

2.333333333333
2.333333333333
2147891.987809741870

result:

wrong answer 1st numbers differ - expected: '0.7777778', found: '2.3333333', error = '1.5555556'