QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#111189 | #6570. Who Watches the Watchmen? | applese | WA | 3ms | 3916kb | C++14 | 7.5kb | 2023-06-06 11:05:44 | 2023-06-06 11:05:45 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const double eps = 1e-9;
const int maxn = 505;
namespace KM {
int n, matched[505], visy[505], lx[505], ly[505], pre[505];
long long e[505][505], slack[505];
void Bfs(int want_match) {
int now, new_match = 0, x = 0;
memset(pre, 0, sizeof pre);
memset(slack, 0x3f, sizeof slack);
matched[x] = want_match;
do {
now = matched[x];
long long delta = 1e18;
visy[x] = true;
for(int i = 1; i <= n; ++ i) {
if(!visy[i]) {
if(slack[i] > lx[now] + ly[i] - e[now][i]) {
slack[i] = lx[now] + ly[i] - e[now][i];
pre[i] = x;
}
if(slack[i] < delta) {
delta = slack[i];
new_match = i;
}
}
}
// cerr << " " << n << " " << new_match << " " << x << " " << matched[x] << " " << now << endl;
for(int i = 0; i <= n; ++ i) {
if(visy[i]) {
lx[matched[i]] -= delta;
ly[i] += delta;
}
else {
slack[i] -= delta;
}
}
x = new_match;
} while(matched[x]);
while(x) {
matched[x] = matched[pre[x]];
x = pre[x];
}
}
long long KM() {
memset(matched, 0, sizeof matched);
memset(lx, 0, sizeof lx);
memset(ly, 0, sizeof ly);
for(int i = 1; i <= n; ++ i) {
memset(visy, 0, sizeof visy);
Bfs(i);
}
// for(int i = 1; i <= n; ++ i)
// cerr << matched[i] << " " << i << endl;
long long ans = 0;
for(int i = 1; i <= n; ++ i)
ans += e[matched[i]][i];
return ans;
}
}
int Dcmp(double x) {
return x < -eps ? -1 : x > eps ? 1 : 0;
}
int n, id[maxn];
struct Point {
double x, y, z;
Point(double x = 0, double y = 0, double z = 0) : x(x), y(y), z(z) {}
bool operator == (const Point &rhs) const {
return Dcmp(x - rhs.x) == 0 && Dcmp(y - rhs.y) == 0 && Dcmp(z - rhs.z) == 0;
}
bool operator < (const Point &rhs) const {
return Dcmp(x - rhs.x) == 0 ? (Dcmp(y - rhs.y) == 0 ? Dcmp(z - rhs.z) < 0 : Dcmp(y - rhs.y) < 0) : Dcmp(x - rhs.x) < 0;
}
Point operator + (const Point &rhs) const {
return Point(x + rhs.x, y + rhs.y, z + rhs.z);
}
Point operator - (const Point &rhs) const {
return Point(x - rhs.x, y - rhs.y, z - rhs.z);
}
Point operator * (const double &k) const {
return Point(x * k, y * k, z * k);
}
Point operator / (const double &k) const {
return Point(x / k, y / k, z / k);
}
double operator * (const Point &rhs) const {
return x * rhs.x + y * rhs.y + z * rhs.z;
}
Point operator ^ (const Point &rhs) const {
return Point(y * rhs.z - z * rhs.y, z * rhs.x - x * rhs.z, x * rhs.y - y * rhs.x);
}
double len2() {
return x * x + y * y + z * z;
}
double len() {
return sqrt(len2());
}
Point Unit() {
return (*this) / len();
}
}p[maxn], v[maxn], np[maxn], nv[maxn];
struct Line {
Point s, t;
Line(Point s = Point(), Point t = Point()) : s(s), t(t) {}
double len2() {
return (t - s).len2();
}
double len() {
return (t - s).len();
}
};
double Area(Point a, Point b, Point c) {
return ((b - a) ^ (c - a)).len();
}
int PointOnSeg(Point p, Line l) {
return Dcmp(((l.s - p) ^ (l.t - p)).len2()) == 0 && Dcmp((l.s - p) * (l.t - p)) <= 0;
}
Point LinePro(Point p, Line l) {
return l.s + (((l.t - l.s) * ((l.t - l.s) * (p - l.s))) / (l.len2()));
}
int SegInterSeg(Line x, Line y) {
double a = (x.t - x.s) * (x.t - x.s);
double b = (x.t - x.s) * (y.t - y.s);
double e = (y.t - y.s) * (y.t - y.s);
double d = a * e - b * b;
Point r = x.s - y.s;
double c = (x.t - x.s) * r, f = (y.t - y.s) * r;
if(Dcmp(d) == 0)
return 0;
double s = (b * f - c * e) / d, t = (a * f - c * b) / d;
Point g = x.s + (x.t - x.s) * s, h = y.s + (y.t - y.s) * t;
if(PointOnSeg(g, x) && PointOnSeg(h, y))
return Dcmp((g - h).len2()) == 0;
return 0;
}
struct Plane {
Point a, b, c, o;
Plane(){}
Plane(Point a, Point b, Point c) : a(a), b(b), c(c) {
o = Pvec();
}
Point Pvec() {
return (b - a) ^ (c - a);
}
};
int PointOnPlane(Point p, Plane pl) {
return Dcmp((p - pl.a) * pl.o) == 0;
}
int spre[maxn], ssuf[maxn], spre2[maxn], ssuf2[maxn];
int main() {
scanf("%d", &n);
for(int i = 1, x, y, z; i <= n; ++ i) {
scanf("%d%d%d", &x, &y, &z);
p[i] = Point(x, y, z);
scanf("%d%d%d", &x, &y, &z);
v[i] = Point(x, y, z);
}
int l = 1;
for(int i = 3; i <= n; ++ i) {
if(Dcmp(Area(p[1], p[2], p[i]))) {
l = 0;
break;
}
}
if(n % 2 == 0 || !l) {
KM :: n = n;
int hav = 0, inf = 0;
for(int i = 1; i <= n; ++ i) {
for(int j = 1; j <= n; ++ j) {
KM :: e[i][j] = inf - 1e9;
if(i == j)
continue;
int ons = 0;
for(int k = 1; k <= n; ++ k) {
if(i != k && j != k) {
if(PointOnSeg(p[k], Line(p[i], p[j]))) {
ons = 1;
break;
}
}
}
if(!ons) {
if((p[j] - p[i]).Unit() == v[i].Unit()) {
++ hav;
KM :: e[i][j] = inf + 1;
}
else {
KM :: e[i][j] = inf;
}
}
// cerr << i << " " << j << " " << KM :: e[i][j] << endl;
}
}
long long ans = KM :: KM() - 1ll * n * inf;
// cerr << hav << " " << ans << endl;
assert(ans >= 0);
printf("%lld\n", hav - ans + n - ans);
}
else {
int res = 1e9;
for(int i = 1; i <= n; ++ i) {
int m = 0;
for(int j = 1; j <= n; ++ j) {
if(i != j) {
++ m;
np[m] = p[j];
nv[m] = v[j];
id[m] = m;
}
}
sort(id + 1, id + m + 1, [&](int a, int b) {
return np[a] < np[b];
});
for(int j = 0; j <= m + 2; ++ j) {
spre[j] = 0;
ssuf[j] = 0;
spre2[j] = 0;
ssuf2[j] = 0;
}
for(int j = 1; j < m; ++ j) {
int x = 1;
if((np[id[j + 1]] - np[id[j]]).Unit() == nv[id[j]].Unit()) {
x = 0;
}
spre[j] = spre[j - 1] + x;
spre2[j] = (j > 1 ? spre2[j - 2] : 0) + x;
}
for(int j = m; j > 1; -- j) {
int x = 1;
if((np[id[j - 1]] - np[id[j]]).Unit() == nv[id[j]].Unit()) {
x = 0;
}
ssuf[j] = ssuf[j + 1] + x;
ssuf2[j] = ssuf2[j + 2] + x;
}
for(int l = 1; l <= m; l += 2) {
for(int r = l + 1; r <= m; r += 2) {
int ans = 1000;
if(l > 1)
ans += spre2[l - 2] + ssuf2[2] - ssuf2[l + 1];
if(r < m)
ans += ssuf2[r + 2] + spre2[m - 1] - spre2[r - 1];
int ansl = spre[r - 1] - spre[l - 1], ansr = ssuf[l + 1] - ssuf[r + 1];
if(Dcmp(((np[id[m]] - np[id[1]]) ^ (v[i])).len()) == 0 && Dcmp(((np[id[m]] - np[id[1]]) ^ (nv[id[r]])).len()) == 0)
ansl += 2;
else {
ansl += 1;
if(Dcmp(((np[id[m]] - np[id[1]]) ^ (v[i])).len()) != 0 && Dcmp(((np[id[m]] - np[id[1]]) ^ (nv[id[r]])).len()) != 0) {
Plane p = Plane(np[id[l]], np[id[r]], np[id[r]] + nv[id[r]]);
if(PointOnPlane(np[id[r]] + v[i], p)) {
Line l1 = Line(np[id[r]], np[id[r]] + (nv[id[r]].Unit() * 1e7)), l2 = Line(np[id[l]], np[id[l]] - (v[i].Unit() * 1e7));
if(SegInterSeg(l1, l2))
-- ansl;
}
}
}
if(Dcmp(((np[id[m]] - np[id[1]]) ^ (v[i])).len()) == 0 && Dcmp(((np[id[m]] - np[id[1]]) ^ (nv[id[l]])).len()) == 0)
ansr += 2;
else {
ansr += 1;
if(Dcmp(((np[id[m]] - np[id[1]]) ^ (v[i])).len()) != 0 && Dcmp(((np[id[m]] - np[id[1]]) ^ (nv[id[l]])).len()) != 0) {
Plane p = Plane(np[id[l]], np[id[r]], np[id[l]] + nv[id[l]]);
if(!PointOnPlane(np[id[l]] + v[i], p)) {
Line l1 = Line(np[id[l]], np[id[l]] + (nv[id[l]].Unit() * 1e7)), l2 = Line(np[id[r]], np[id[r]] - (v[i].Unit() * 1e7));
if(SegInterSeg(l1, l2))
-- ansr;
}
}
}
ans += min(ansl, ansr);
res = min(res, ans);
}
}
}
printf("%d\n", res);
}
}
詳細信息
Test #1:
score: 100
Accepted
time: 2ms
memory: 3908kb
input:
7 0 0 0 1 0 0 1 0 0 -1 0 0 2 0 0 1 0 0 3 0 0 1 0 0 4 0 0 1 0 0 5 0 0 1 0 0 6 0 0 -1 0 0
output:
1002
result:
ok single line: '1002'
Test #2:
score: 0
Accepted
time: 3ms
memory: 3684kb
input:
4 66 45 10 73 39 36 95 14 26 47 84 59 14 66 89 89 36 78 16 27 94 79 24 24
output:
4
result:
ok single line: '4'
Test #3:
score: 0
Accepted
time: 2ms
memory: 3916kb
input:
3 0 0 0 1 0 0 1 1 1 1 0 0 2 2 2 1 0 0
output:
1002
result:
ok single line: '1002'
Test #4:
score: 0
Accepted
time: 0ms
memory: 3672kb
input:
3 0 0 0 1 1 1 1 1 1 1 0 0 2 2 2 1 0 0
output:
1001
result:
ok single line: '1001'
Test #5:
score: 0
Accepted
time: 2ms
memory: 3892kb
input:
3 0 0 0 1 0 0 1 1 1 1 0 0 2 2 2 -1 -1 -1
output:
1001
result:
ok single line: '1001'
Test #6:
score: -100
Wrong Answer
time: 2ms
memory: 3724kb
input:
3 0 0 0 1 0 0 1 1 1 1 2 2 2 2 2 -1 -1 -1
output:
1001
result:
wrong answer 1st lines differ - expected: '1000', found: '1001'