QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#299045#7903. Computational Intelligenceucup-team087#WA 1211ms3948kbC++147.5kb2024-01-06 16:53:522024-01-06 16:53:53

Judging History

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

  • [2024-01-06 16:53:53]
  • 评测
  • 测评结果:WA
  • 用时:1211ms
  • 内存:3948kb
  • [2024-01-06 16:53:52]
  • 提交

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;

inline int sig(Double r) { return (r < -EPS) ? -1 : (r > +EPS) ? +1 : 0; }
inline Double sq(Double r) { return r * r; }

struct Pt {
  Double x, y;
  Pt() {}
  Pt(Double x_, Double y_) : x(x_), y(y_) {}
  Pt operator+(const Pt &a) const { return Pt(x + a.x, y + a.y); }
  Pt operator-(const Pt &a) const { return Pt(x - a.x, y - a.y); }
  Pt operator*(const Pt &a) const { return Pt(x * a.x - y * a.y, x * a.y + y * a.x); }
  Pt operator/(const Pt &a) const { const Double d2 = a.abs2(); return Pt((x * a.x + y * a.y) / d2, (y * a.x - x * a.y) / d2); }
  Pt operator+() const { return Pt(+x, +y); }
  Pt operator-() const { return Pt(-x, -y); }
  Pt operator*(const Double &k) const { return Pt(x * k, y * k); }
  Pt operator/(const Double &k) const { return Pt(x / k, y / k); }
  friend Pt operator*(const Double &k, const Pt &a) { return Pt(k * a.x, k * a.y); }
  Pt &operator+=(const Pt &a) { x += a.x; y += a.y; return *this; }
  Pt &operator-=(const Pt &a) { x -= a.x; y -= a.y; return *this; }
  Pt &operator*=(const Pt &a) { return *this = *this * a; }
  Pt &operator/=(const Pt &a) { return *this = *this / a; }
  Pt &operator*=(const Double &k) { x *= k; y *= k; return *this; }
  Pt &operator/=(const Double &k) { x /= k; y /= k; return *this; }
  Double abs() const { return sqrt(x * x + y * y); }
  Double abs2() const { return x * x + y * y; }
  Double arg() const { return atan2(y, x); }
  Double dot(const Pt &a) const { return x * a.x + y * a.y; }
  Double det(const Pt &a) const { return x * a.y - y * a.x; }
  friend ostream &operator<<(ostream &os, const Pt &a) { os << "(" << a.x << ", " << a.y << ")"; return os; }
};
inline Double tri(const Pt &a, const Pt &b, const Pt &c) { return (b - a).det(c - a); }


int iSP(const Pt &a, const Pt &b, const Pt &c) {
	int s = sig((b - a).det(c - a));
	if (s != 0) return s;
	if (sig((b - a).dot(c - a)) < 0) return -2; // c-a-b
	if (sig((a - b).dot(c - b)) < 0) return +2; //   a-b-c
	return 0;
}
int iLL(const Pt &a, const Pt &b, const Pt &c, const Pt &d) {
	if (sig((b - a).det(d - c))) return 1;	//	intersect
	if (sig((b - a).det(c - a))) return 0;	//	parallel
	return -1;	//	correspond
}

Pt pLL(const Pt &a, const Pt &b, const Pt &c, const Pt &d) {
  const Pt ab = b - a, cd = d - c;
  return a + ab * (c - a).det(cd) / ab.det(cd);
}
Double pLL2(const Pt &a, const Pt &b, const Pt &c, const Pt &d) {
  const Pt ab = b - a, cd = d - c;
  return (c - a).det(cd) / ab.det(cd);
}


constexpr int N = 300;
constexpr int M = 300;

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;
    }
    
    // kouten
    Pt P[4];
    for (int i = 0; i < 4; ++i) P[i] = Pt(X[i][0], X[i][1]);
    int I0 = -1;
    if (iLL(P[0], P[1], P[2], P[3]) == 1) {
      const Double s = pLL2(
        Pt(X[0][0], X[0][1]),
        Pt(X[1][0], X[1][1]),
        Pt(X[2][0], X[2][1]),
        Pt(X[3][0], X[3][1])
      );
      if (0 <= s && s <= 1) {
        I0 = min(max((int)(s * N), 0), N - 1);
// printf("kouten s = %f, I0 = %d\n",s,I0);
      }
    }
    
    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) {
      // if (d <= 0) {
        // 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)));
        return sa/2 * ((r*sr - l*sl) - d * log((sl + l) / (sr + r)));
      }
    };
    
    // [l/N, r/N]
    auto easy = [&](int l, int r) -> Double {
      if (l == r) return 0.0;
      Double ret = 0.0;
      for (int i = 2*l; i <= 2*r; ++i) {
        const int coef = (i == 2*l || i == 2*r) ? 1 : (i % 2 == 0) ? 2 : 4;
        const Double res = calc(1.0 / (2*N) * i);
        ret += coef * res;
      }
      ret *= (1.0 / (2*N));
      ret /= 3.0;
      return ret;
    };
    auto hard = [&](int l, int r) -> Double {
      if (l == r) return 0.0;
      const Double sL = 1.0 / N * l;
      const Double sR = 1.0 / N * r;
      Double ret = 0.0;
      for (int j = 0; j <= 2*M; ++j) {
        const int coef = (j == 0 || j == 2*M) ? 1 : (j % 2 == 0) ? 2 : 4;
        const Double res = calc(sL + (sR - sL) / (2*M) * j);
        ret += coef * res;
      }
      ret *= ((sR - sL) / (2*M));
      ret /= 3.0;
      return ret;
    };
    
    Double ans = 0.0;
    // if (~I0) {
    if(0){
      int l = I0 - 1, r = I0 + 2;
      chmax(l, 0);
      chmin(r, N);
// cerr<<"l = "<<l<<", r = "<<r<<endl;
      ans += easy(0, l);
      ans += hard(l, r);
      ans += easy(r, N);
    } else {
      ans += easy(0, N);
    }
// cerr<<"easy(0,N) = "<<easy(0,N)<<endl;
// cerr<<"hard(0,N) = "<<hard(0,N)<<endl;
    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: 3948kb

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

result:

ok 3 numbers

Test #2:

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

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.070405024588

result:

ok 3 numbers

Test #3:

score: -100
Wrong Answer
time: 1211ms
memory: 3912kb

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.744131449251
14.594278702892
2.952178242510
4.993502695108
6.058717257857
7.459408700246
11.228028907919
16.325707847495
11.072245157190
9.504557451155
5.500000000000
9.040049985829
5.326347910887
3.035934371289
5.808804190441
17.363719789522
9.995194519237
6.993302622881
6.55043322...

result:

wrong answer 16th numbers differ - expected: '5.8088042', found: '5.8088042', error = '0.0000000'