QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#299011 | #7903. Computational Intelligence | ucup-team087# | WA | 0ms | 3932kb | C++14 | 7.2kb | 2024-01-06 16:39:21 | 2024-01-06 16:39:22 |
Judging History
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 = 200;
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) {
// 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)));
}
};
auto easy = [&](int l, int r) -> Double {
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 {
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) {
int l = I0 - 1, r = I0 + 2;
chmax(l, 0);
chmin(r, N);
ans += easy(0, l);
ans += hard(l, r);
ans += easy(r, N);
} else {
ans += easy(0, N);
}
printf("%.12f\n", ans);
}
#ifndef LOCAL
break;
#endif
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3932kb
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.765612383152 1.076635732895
result:
wrong answer 2nd numbers differ - expected: '0.7651957', found: '0.7656124', error = '0.0004167'