QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#299274#7903. Computational Intelligenceucup-team087TL 1475ms4084kbC++147.9kb2024-01-06 18:18:412024-01-06 18:18:42

Judging History

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

  • [2024-01-06 18:18:42]
  • 评测
  • 测评结果:TL
  • 用时:1475ms
  • 内存:4084kb
  • [2024-01-06 18:18:41]
  • 提交

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-11;

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 = 350;
constexpr int M = 10;

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]);
    
    if ((P[1] - P[0]).abs2() > (P[3] - P[2]).abs2()) {
      for (int j = 0; j < 2; ++j) swap(X[0][j], X[2][j]);
      for (int j = 0; j < 2; ++j) swap(X[1][j], X[3][j]);
      swap(P[0], P[2]);
      swap(P[1], P[3]);
    }
    
    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 <= 0) {
        if (0 <= l) {
          return sa/2 * (r*r - l*l);
        } else if (r <= 0) {
          return sa/2 * (l*l - r*r);
        } else {
          return sa/2 * (l*l + r*r);
        }
      //*
      } else if (d <= EPS) {
        if (0 < l) {
          return sa/2 * ((r*r - l*l) + d/2 * log(max(r, +EPS) / max(l, +EPS)));
        } else if (r < 0) {
          return sa/2 * ((l*l - r*r) + d/2 * log(min(l, -EPS) / min(r, -EPS)));
        } else {
          return sa/2 * ((l*l + r*r) + d/2 * log(-min(l, -EPS) * max(r, +EPS) / (EPS*EPS)));
        }
      //*/
      } 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)));
        return sa/2 * ((r*sr - l*sl) - d * log(max(sr - r, EPS) / max(sl - l, EPS)));
      }
    };
    
    // [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", (double)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: 3812kb

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

result:

ok 3 numbers

Test #2:

score: 0
Accepted
time: 0ms
memory: 3944kb

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

result:

ok 3 numbers

Test #3:

score: 0
Accepted
time: 1468ms
memory: 3980kb

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.744131448898
14.594278702892
2.952178245517
4.993502694125
6.058717255534
7.459408700250
11.228028907920
16.325707847495
11.072245157190
9.504557451156
5.500000000000
9.040049985829
5.326347910887
3.035934371290
5.808804183058
17.363719789522
9.995194519237
6.993302622881
6.55043322...

result:

ok 100000 numbers

Test #4:

score: 0
Accepted
time: 1460ms
memory: 3772kb

input:

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

output:

6.516226342417
7.895152181059
7.619252804124
6.272101354102
10.676587784394
4.048146349223
13.704168816509
5.960724885256
4.752273723772
5.808486858335
6.049334617408
4.212001303540
5.231052190723
7.816888558915
4.839493440445
6.085980058681
8.540849032637
6.899466200895
5.198575702566
7.92716381072...

result:

ok 100000 numbers

Test #5:

score: 0
Accepted
time: 920ms
memory: 3892kb

input:

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

output:

4.533823502912
7.905694150421
3.399346342395
0.942809041582
8.062257748299
9.848857801796
6.500000000000
6.699917080747
4.533823502912
5.830951894845
6.016087653749
5.467073155619
5.676462121975
3.800584750330
5.517648452416
3.887301263230
2.603416558636
4.333333333333
2.867441755681
3.518518518303
...

result:

ok 100000 numbers

Test #6:

score: 0
Accepted
time: 921ms
memory: 3884kb

input:

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

output:

6.523809523810
4.013864859597
7.500000000000
5.507010122909
2.748737083745
2.687419249433
3.901566636907
2.108185106779
4.333333333333
2.357022603955
4.176654695381
5.059644256269
3.484848484848
3.144660377352
4.027681991198
7.923222137911
2.357022603955
5.734883511362
2.981423970000
3.887301263230
...

result:

ok 100000 numbers

Test #7:

score: 0
Accepted
time: 1457ms
memory: 4080kb

input:

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

output:

6.044841559803
8.806908441629
7.211988492479
9.705894454248
5.879889741481
11.751734336573
7.387327468522
7.552508251824
4.795900553897
4.585511109976
11.636587321970
6.539467273582
8.155918942813
6.932750626180
3.744379817400
11.401172906234
16.839940311399
14.410838201436
6.386042190398
10.8509848...

result:

ok 100000 numbers

Test #8:

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

input:

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

output:

6.797092276544
12.429172495107
8.976426143538
7.486123031632
7.130299838219
6.028769291778
4.087930934617
4.823038522432
6.123128729386
7.246635688914
7.724226961177
10.316193728710
5.124308856571
4.791595303088
3.302047238926
2.312246344813
8.410214920625
13.517584456800
8.533966057092
8.5450889120...

result:

ok 100000 numbers

Test #9:

score: 0
Accepted
time: 893ms
memory: 3940kb

input:

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

output:

5.011098792791
6.749485577106
4.346134936802
4.333333333333
5.270462766947
3.282952600599
3.726779962500
2.687419249433
1.943650631615
5.099019513593
2.108185106779
5.217491947500
5.587684871413
6.839428176228
1.699673171198
6.324555320337
3.431876713662
2.828427124746
5.666666666667
4.921607686744
...

result:

ok 100000 numbers

Test #10:

score: 0
Accepted
time: 1475ms
memory: 4084kb

input:

100000
50 -71 4 90
-69 -29 12 -1
-98 -38 -10 34
-40 -94 48 19
-2 36 -25 -55
-56 38 -22 -84
-80 -18 28 63
1 -14 74 -19
73 59 76 -61
-52 -28 -97 -91
-9 -54 89 33
-65 93 -64 12
-65 -77 79 87
-95 -40 49 -61
-88 -97 47 83
59 65 -30 -35
-55 59 89 -91
27 98 -17 93
-49 84 74 -90
37 4 -59 -18
72 -27 63 -34
9...

output:

77.596705004729
83.979645362576
49.327207070993
83.974820099519
163.879147592891
128.662991662278
86.719766611342
72.434035081342
120.317190035193
65.378944997015
38.467358046173
142.394344968573
172.484435283356
88.797397645167
103.861006339023
112.660658340550
53.222933957128
53.750870341578
119.3...

result:

ok 100000 numbers

Test #11:

score: -100
Time Limit Exceeded

input:

100000
74 50 60 -48
-17 -68 74 50
57 80 36 23
-1 -98 57 80
94 -87 4 1
4 1 44 -70
8 90 -93 -87
-93 -87 10 -51
56 -56 43 -16
56 -56 49 20
56 -21 85 24
56 -21 -45 24
46 -83 67 -90
46 -83 -96 -54
7 -59 -81 95
52 -63 -81 95
-96 -74 -6 92
-6 92 -100 72
91 33 -9 55
-9 55 -27 5
30 36 58 -40
88 -31 30 36
49 ...

output:

58.366697243158
69.863330974219
43.490764400886
87.084290278505
26.087927019382
68.005214731292
83.472363923873
69.433387650765
86.012446756014
63.715166111848
33.878784640375
62.029070851063
66.298085751789
34.852023277617
40.565384049304
68.634388327682
69.446066473601
85.792227570713
88.739697776...

result: