QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#338713 | #2433. Panda Preserve | lmf_up | AC ✓ | 1064ms | 4680kb | C++20 | 4.7kb | 2024-02-26 09:03:06 | 2024-02-26 09:03:06 |
Judging History
answer
#include <bits/stdc++.h>
using std::cin;
using std::cout;
using ll = long long;
using u64 = unsigned long long;
using db = double;
const db eps = 1e-4;
const db pi = std::acos(-1);
std::mt19937 gen;
db sgn(db x, db eps) {
return x < -eps ? -1 : x > eps;
}
db sgn(db x) {
return x < -eps ? -1 : x > eps;
}
db eq(db x, db y) {
return !sgn(x - y);
}
struct vec2 {
db x, y;
db abs() const {
return std::sqrt(x * x + y * y);
}
};
vec2 r90(vec2 x) {
return {-x.y, x.x};
}
vec2 operator + (vec2 x, vec2 y) {
return {x.x + y.x, x.y + y.y};
}
vec2 operator - (vec2 x, vec2 y) {
return {x.x - y.x, x.y - y.y};
}
vec2 operator / (vec2 x, db y) {
return {x.x / y, x.y / y};
}
vec2 operator * (vec2 x, db y) {
return {x.x * y, x.y * y};
}
db operator * (vec2 x, vec2 y) {
return x.x * y.y - x.y * y.x;
}
db operator % (vec2 x, vec2 y) {
return x.x * y.x + x.y * y.y;
}
struct line : vec2 {
db z;
line() = default;
line(db a, db b, db c) : vec2{a, b}, z(c) {}
line(vec2 a, vec2 b) : vec2(r90(b - a)), z(a * b) { }
db operator()(vec2 a) const {
return a % vec2(*this) + z;
}
line perp() const {
return {y, -x, 0}; // 垂直
}
line para(vec2 o) {
return {x, y, z - (*this)(o)}; // 平行
}
};
vec2 operator & (line x, line y) {
return vec2{vec2{x.z, x.y} *vec2{y.z, y.y}, vec2{x.x, x.z} *vec2{y.x, y.z}} / -(vec2(x) * vec2(y));
}
line bisector(vec2 x, vec2 y) {
return line(y, x).perp().para((x + y) / 2); // x 在半平面一侧
}
bool is_para(line x, line y) {
return eq(vec2(x) * vec2(y), 0); // 判断线平行
}
db det(line a, line b, line c) {
vec2 A = a, B = b, C = c;
return c.z * (A * B) + a.z * (B * C) + b.z * (C * A);
}
db check(line a, line b, line c) {
return sgn(det(a, b, c), 0.5) * sgn(vec2(a) * vec2(b));
}
struct seg {
vec2 x, y;
seg(const vec2 &A, const vec2 &B) : x(A), y(B) {}
bool onseg(const vec2 &o) const {
return (o - x) % (o - y) < eps && std::fabs((o - x) * (o - y)) < eps;
}
};
int contain(const std::vector<vec2> &a, vec2 o) {
bool in = 0;
for (int i = 0; i < (int) a.size(); ++i) {
vec2 x = a[i] - o, y = a[(i + 1) % a.size()] - o;
if (x.y > y.y)
std::swap(x, y);
if (x.y <= eps && y.y > eps && x * y < -eps)
in ^= 1;
if (std::fabs(x * y) < eps && x % y < eps)
return 2; // 在线段上,看情况改
}
return in;
}
std::vector<line> cut(const std::vector<line> &o, line l) {
std::vector<line> res;
int n = size(o);
for (int i = 0; i < n; ++i) {
line a = o[i], b = o[(i + 1) % n], c = o[(i + 2) % n];
int va = check(a, b, l), vb = check(b, c, l);
// assert(check(a, b, c) != 0);
if (va > 0 || vb > 0 || (va == 0 && vb == 0)) {
res.push_back(b);
}
if (va >= 0 && vb < 0) {
res.push_back(l);
}
}
return res;
}
std::vector<std::vector<line>> voronoi(std::vector<vec2> p) {
int n = p.size();
auto b = p;
shuffle(b.begin(), b.end(), gen);
const db V = 3e4;
std::vector<std::vector<line>> a(n, {
{V, 0, V * V}, {0, V, V * V},
{-V, 0, V * V}, {0, -V, V * V},
});
for (int i = 0; i < n; ++i) {
for (vec2 x : b)
if ((x - p[i]).abs() > eps) {
a[i] = cut(a[i], bisector(p[i], x));
}
}
return a;
}
int main() {
std::ios::sync_with_stdio(false), cin.tie(0);
int n;
cin >> n;
std::vector<vec2> a(n);
for (int i = 0; i < n; ++i) {
cin >> a[i].x >> a[i].y;
}
auto vd = voronoi(a);
db ans = 0;
for (int i = 0; i < n; ++i) {
auto v = vd[i];
int m = v.size();
std::vector<vec2> o(m);
for (int j = 0; j < m; ++j) {
o[j] = v[j] & v[(j + 1) % m];
}
for (auto x : o) {
if (contain(a, x)) {
ans = std::max(ans, (x - a[i]).abs());
}
}
for (int j = 0; j < m; ++j) {
seg x = {o[j], o[(j + 1) % m]};
for (int k = 0; k < n; ++k) {
seg y = {a[k], a[(k + 1) % n]};
line X(x.x, x.y);
line Y(y.x, y.y);
if (is_para(X, Y))
continue;
vec2 z = X & Y;
if (x.onseg(z) && y.onseg(z))
ans = std::max(ans, (z - a[i]).abs());
}
}
}
printf("%.9lf\n", ans);
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 3932kb
Test #2:
score: 0
Accepted
time: 0ms
memory: 3984kb
Test #3:
score: 0
Accepted
time: 1ms
memory: 3956kb
Test #4:
score: 0
Accepted
time: 0ms
memory: 3812kb
Test #5:
score: 0
Accepted
time: 0ms
memory: 3748kb
Test #6:
score: 0
Accepted
time: 1ms
memory: 3920kb
Test #7:
score: 0
Accepted
time: 0ms
memory: 4096kb
Test #8:
score: 0
Accepted
time: 0ms
memory: 3812kb
Test #9:
score: 0
Accepted
time: 0ms
memory: 3956kb
Test #10:
score: 0
Accepted
time: 0ms
memory: 4100kb
Test #11:
score: 0
Accepted
time: 0ms
memory: 3988kb
Test #12:
score: 0
Accepted
time: 1ms
memory: 3964kb
Test #13:
score: 0
Accepted
time: 0ms
memory: 3924kb
Test #14:
score: 0
Accepted
time: 0ms
memory: 4092kb
Test #15:
score: 0
Accepted
time: 0ms
memory: 3756kb
Test #16:
score: 0
Accepted
time: 0ms
memory: 4116kb
Test #17:
score: 0
Accepted
time: 0ms
memory: 3820kb
Test #18:
score: 0
Accepted
time: 0ms
memory: 4016kb
Test #19:
score: 0
Accepted
time: 0ms
memory: 3984kb
Test #20:
score: 0
Accepted
time: 0ms
memory: 3956kb
Test #21:
score: 0
Accepted
time: 0ms
memory: 3920kb
Test #22:
score: 0
Accepted
time: 0ms
memory: 3932kb
Test #23:
score: 0
Accepted
time: 0ms
memory: 4096kb
Test #24:
score: 0
Accepted
time: 0ms
memory: 3812kb
Test #25:
score: 0
Accepted
time: 0ms
memory: 3924kb
Test #26:
score: 0
Accepted
time: 0ms
memory: 3932kb
Test #27:
score: 0
Accepted
time: 1ms
memory: 4024kb
Test #28:
score: 0
Accepted
time: 1ms
memory: 3756kb
Test #29:
score: 0
Accepted
time: 1ms
memory: 3752kb
Test #30:
score: 0
Accepted
time: 0ms
memory: 3928kb
Test #31:
score: 0
Accepted
time: 1ms
memory: 3988kb
Test #32:
score: 0
Accepted
time: 1ms
memory: 4108kb
Test #33:
score: 0
Accepted
time: 1ms
memory: 3756kb
Test #34:
score: 0
Accepted
time: 1ms
memory: 3996kb
Test #35:
score: 0
Accepted
time: 1ms
memory: 3812kb
Test #36:
score: 0
Accepted
time: 0ms
memory: 3992kb
Test #37:
score: 0
Accepted
time: 1ms
memory: 3960kb
Test #38:
score: 0
Accepted
time: 1ms
memory: 3988kb
Test #39:
score: 0
Accepted
time: 0ms
memory: 3924kb
Test #40:
score: 0
Accepted
time: 1ms
memory: 3928kb
Test #41:
score: 0
Accepted
time: 1ms
memory: 4096kb
Test #42:
score: 0
Accepted
time: 1ms
memory: 3988kb
Test #43:
score: 0
Accepted
time: 1ms
memory: 3932kb
Test #44:
score: 0
Accepted
time: 1ms
memory: 4020kb
Test #45:
score: 0
Accepted
time: 0ms
memory: 3812kb
Test #46:
score: 0
Accepted
time: 1ms
memory: 4104kb
Test #47:
score: 0
Accepted
time: 0ms
memory: 3808kb
Test #48:
score: 0
Accepted
time: 1ms
memory: 3804kb
Test #49:
score: 0
Accepted
time: 1ms
memory: 3816kb
Test #50:
score: 0
Accepted
time: 1ms
memory: 3808kb
Test #51:
score: 0
Accepted
time: 1ms
memory: 3812kb
Test #52:
score: 0
Accepted
time: 1ms
memory: 3988kb
Test #53:
score: 0
Accepted
time: 63ms
memory: 3956kb
Test #54:
score: 0
Accepted
time: 257ms
memory: 4252kb
Test #55:
score: 0
Accepted
time: 4ms
memory: 4024kb
Test #56:
score: 0
Accepted
time: 71ms
memory: 4132kb
Test #57:
score: 0
Accepted
time: 298ms
memory: 4140kb
Test #58:
score: 0
Accepted
time: 4ms
memory: 3844kb
Test #59:
score: 0
Accepted
time: 75ms
memory: 4136kb
Test #60:
score: 0
Accepted
time: 191ms
memory: 4428kb
Test #61:
score: 0
Accepted
time: 2ms
memory: 3984kb
Test #62:
score: 0
Accepted
time: 35ms
memory: 4072kb
Test #63:
score: 0
Accepted
time: 133ms
memory: 4228kb
Test #64:
score: 0
Accepted
time: 0ms
memory: 3808kb
Test #65:
score: 0
Accepted
time: 0ms
memory: 3928kb
Test #66:
score: 0
Accepted
time: 0ms
memory: 3984kb
Test #67:
score: 0
Accepted
time: 0ms
memory: 3928kb
Test #68:
score: 0
Accepted
time: 605ms
memory: 4456kb
Test #69:
score: 0
Accepted
time: 0ms
memory: 3816kb
Test #70:
score: 0
Accepted
time: 610ms
memory: 4328kb
Test #71:
score: 0
Accepted
time: 38ms
memory: 4096kb
Test #72:
score: 0
Accepted
time: 530ms
memory: 4336kb
Test #73:
score: 0
Accepted
time: 107ms
memory: 4056kb
Test #74:
score: 0
Accepted
time: 547ms
memory: 4228kb
Test #75:
score: 0
Accepted
time: 122ms
memory: 4144kb
Test #76:
score: 0
Accepted
time: 7ms
memory: 3808kb
Test #77:
score: 0
Accepted
time: 3ms
memory: 3856kb
Test #78:
score: 0
Accepted
time: 7ms
memory: 3868kb
Test #79:
score: 0
Accepted
time: 7ms
memory: 3864kb
Test #80:
score: 0
Accepted
time: 3ms
memory: 3872kb
Test #81:
score: 0
Accepted
time: 7ms
memory: 3872kb
Test #82:
score: 0
Accepted
time: 7ms
memory: 4048kb
Test #83:
score: 0
Accepted
time: 7ms
memory: 3868kb
Test #84:
score: 0
Accepted
time: 7ms
memory: 3872kb
Test #85:
score: 0
Accepted
time: 3ms
memory: 3836kb
Test #86:
score: 0
Accepted
time: 3ms
memory: 3756kb
Test #87:
score: 0
Accepted
time: 7ms
memory: 4016kb
Test #88:
score: 0
Accepted
time: 7ms
memory: 3860kb
Test #89:
score: 0
Accepted
time: 7ms
memory: 3872kb
Test #90:
score: 0
Accepted
time: 7ms
memory: 3864kb
Test #91:
score: 0
Accepted
time: 7ms
memory: 3860kb
Test #92:
score: 0
Accepted
time: 561ms
memory: 4592kb
Test #93:
score: 0
Accepted
time: 786ms
memory: 4280kb
Test #94:
score: 0
Accepted
time: 3ms
memory: 3960kb
Test #95:
score: 0
Accepted
time: 2ms
memory: 3948kb
Test #96:
score: 0
Accepted
time: 6ms
memory: 4040kb
Test #97:
score: 0
Accepted
time: 10ms
memory: 3984kb
Test #98:
score: 0
Accepted
time: 995ms
memory: 4544kb
Test #99:
score: 0
Accepted
time: 867ms
memory: 4396kb
Test #100:
score: 0
Accepted
time: 891ms
memory: 4500kb
Test #101:
score: 0
Accepted
time: 848ms
memory: 4508kb
Test #102:
score: 0
Accepted
time: 833ms
memory: 4680kb
Test #103:
score: 0
Accepted
time: 912ms
memory: 4556kb
Test #104:
score: 0
Accepted
time: 1064ms
memory: 4528kb