forked from oToToT/kiseki
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix min enclosing circle and add tested comment
- Loading branch information
1 parent
e7709e5
commit bd1846c
Showing
1 changed file
with
9 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |