Skip to content

Commit

Permalink
Merge 1efc5e4 into 603d34f
Browse files Browse the repository at this point in the history
  • Loading branch information
OmeletWithoutEgg authored Oct 1, 2023
2 parents 603d34f + 1efc5e4 commit 6007ad6
Show file tree
Hide file tree
Showing 65 changed files with 193 additions and 185 deletions.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
27 changes: 16 additions & 11 deletions codes/Geometry/3d/ConvexHull.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,16 @@ struct P3 { lld x,y,z;
struct Face { int a, b, c;
Face(int ta,int tb,int tc):a(ta),b(tb),c(tc){} };
P3 ver(P3 a, P3 b, P3 c) { return (b - a) * (c - a); }
// plz ensure that first 4 points are not coplanar
// all points coplanar case will WA
vector<Face> convex_hull_3D(const vector<P3> &pt) {
vector<Face> convex_hull_3D(vector<P3> pt) {
int n = int(pt.size()); vector<Face> now;
if (n <= 2) return {}; // be careful about edge case
// ensure first 4 points are not coplanar
#define S(I, E...) swap(pt[I], *find_if(all(pt), \
[&](auto z) { return E; }))
S(1, pt[0] != z);
S(2, ver(z, pt[0], pt[1]) != (P3){0, 0, 0});
S(3, (z - pt[0]).dot(ver(pt[0], pt[1], pt[2])) != 0);
vector<vector<int>> flag(n, vector<int>(n));
now.emplace_back(0,1,2); now.emplace_back(2,1,0);
for (int i = 3; i < n; i++) {
Expand All @@ -22,16 +27,16 @@ vector<Face> convex_hull_3D(const vector<P3> &pt) {
int ff = (d > 0) - (d < 0);
flag[f.a][f.b]=flag[f.b][f.c]=flag[f.c][f.a]=ff;
}
for (const auto &f : now) {
const auto F = [&](int x, int y) {
if (flag[x][y] > 0 && flag[y][x] <= 0)
next.emplace_back(x, y, i);
};
F(f.a, f.b); F(f.b, f.c); F(f.c, f.a);
}
const auto F = [&](int x, int y) {
if (flag[x][y] > 0 && flag[y][x] <= 0)
next.emplace_back(x, y, i);
};
for (const auto &f : now)
F(f.a, f.b), F(f.b, f.c), F(f.c, f.a);
now = next;
}
return now;
}
// delaunay: facets with negative z normal of
// convexhull of (x, y, x^2 + y^2)
// n^2 delaunay: facets with negative z normal of
// convexhull of (x, y, x^2 + y^2), use a pseudo-point
// (0, 0, inf) to avoid degenerate case
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
17 changes: 6 additions & 11 deletions codes/Graph/ManhattanMST.cpp → codes/Misc/ManhattanMST.cpp
Original file line number Diff line number Diff line change
@@ -1,20 +1,15 @@
typedef Point<int> P;
vector<array<int, 3>> manhattanMST(vector<P> ps) {
vi id(sz(ps));
iota(all(id), 0);
vector<int> id(ps.size()); iota(all(id), 0);
vector<array<int, 3>> edges;
rep(k, 0, 4) {
for (int k = 0; k < 4; k++) {
sort(all(id), [&](int i, int j) {
return (ps[i] - ps[j]).x < (ps[j] - ps[i]).y;
});
return (ps[i] - ps[j]).x < (ps[j] - ps[i]).y; });
map<int, int> sweep;
for (int i : id) {
for (auto it = sweep.lower_bound(-ps[i].y);
it != sweep.end(); sweep.erase(it++)) {
int j = it->second;
P d = ps[i] - ps[j];
if (d.y > d.x) break;
edges.push_back({d.y + d.x, i, j});
if (P d = ps[i] - ps[it->second]; d.y > d.x) break;
else edges.push_back({d.y + d.x, i, it->second});
}
sweep[-ps[i].y] = i;
}
Expand All @@ -23,4 +18,4 @@ vector<array<int, 3>> manhattanMST(vector<P> ps) {
else swap(p.x, p.y);
}
return edges; // [{w, i, j}, ...]
}
} // test @ yosupo judge
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit 6007ad6

Please sign in to comment.