Skip to content

Commit

Permalink
Fix min enclosing circle and add tested comment
Browse files Browse the repository at this point in the history
  • Loading branch information
OmeletWithoutEgg committed Oct 5, 2023
1 parent e7709e5 commit bd1846c
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions codes/Geometry/Circle/MinCircleCover.cpp
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
// be careful of type
Cir getCircum(P a, P b, P c){
Cir getCircum(P a, P b, P c){ // P = complex<llf>
P z1 = a - b, z2 = a - c; llf D = cross(z1, z2) * 2;
llf c1 = dot(a + b, z1), c2 = dot(a + c, z2);
P o = (c2 * conj(z1) - c1 * conj(z2)) / D;
P o = rot90(c2 * z1 - c1 * z2) / D;
return { o, abs(o - a) };
}
Cir minCircleCover(vector<P> &pts) {
shuffle(pts.begin(), pts.end(), mt19937(114514));
Cir c = { pts[0], 0 };
for(int i = 0; i < (int)pts.size(); i++) {
assert (!pts.empty());
ranges::shuffle(pts, mt19937(114514));
Cir c = { 0, 0 };
for(size_t i = 0; i < pts.size(); i++) {
if (dist(pts[i], c.o) <= c.r) continue;
c = { pts[i], 0 };
for (int j = 0; j < i; j++) {
for (size_t j = 0; j < i; j++) {
if (dist(pts[j], c.o) <= c.r) continue;
c.o = (pts[i] + pts[j]) / llf(2);
c.r = dist(pts[i], c.o);
for (int k = 0; k < j; k++) {
for (size_t k = 0; k < j; k++) {
if (dist(pts[k], c.o) <= c.r) continue;
c = getCircum(pts[i], pts[j], pts[k]);
}
}
}
return c;
}
} // test @ TIOJ 1093 & luogu P1742

0 comments on commit bd1846c

Please sign in to comment.