# 【做题】POI2011R1 - Plot——最小圆覆盖&倍增

$n,m \leq 10^5$

#include <bits/stdc++.h>
using namespace std;
#define gc() getchar()
template <typename tp>
x = 0; char tmp; bool key = 0;
for (tmp = gc() ; !isdigit(tmp) ; tmp = gc())
key = (tmp == '-');
for ( ; isdigit(tmp) ; tmp = gc())
x = (x << 3) + (x << 1) + (tmp ^ '0');
if (key) x = -x;
}

typedef double db;
const db eps = 1e-8;
inline int jud(db x) {
return x > -eps ? x > eps ? 1 : 0 : -1;
}
struct point {
db x,y;
point(db x_=0, db y_=0): x(x_), y(y_) {}
point operator + (const point& a) const {
return point(x + a.x, y + a.y);
}
point operator - (const point& a) const {
return point(x - a.x, y - a.y);
}
db abs() const {
return sqrt(x * x + y * y);
}
db norm() const {
return x * x + y * y;
}
point perp() const {
return point(- y, x);
}
point operator * (const db& a) const {
return point(x * a, y * a);
}
};
db cross(point a,point b) {
return a.x * b.y - a.y * b.x;
}
db dot(point a,point b) {
return a.x * b.x + a.y * b.y;
}
point unit(point a) {
db d = a.abs();
a.x /= d;
a.y /= d;
return a;
}
struct line {
point u,v;
line(point u_=point(), point v_=point()): u(u_) {
v = unit(v_);
}
};
db dis(point a,line b) {
return cross(a - b.u, b.v);
}
point inse(line a,line b) {
assert(jud(cross(a.v, b.v)) != 0);
db d = dis(a.u, b) / cross(a.v, b.v);
return a.u - (a.v * d);
}
struct circle {
point o;
db r;
circle(point o_=point(), db r_ = 0): o(o_), r(r_) {}
};
circle circum(point a,point b,point c) {
line l1 = line((a + b) * (0.5), (a - b).perp());
line l2 = line((b + c) * (0.5), (b - c).perp());
point d = inse(l1,l2);
return circle(d, (a - d).abs());
}

const int N = 100010;
int n,m,cnt,num;
point po[N], ans[N], tmp[N];
bool check(int l,int r,db x) {
for (int i = l ; i <= r ; ++ i)
tmp[i] = po[i];
random_shuffle(tmp+l,tmp+r+1);
circle cir = circle(tmp[l], 0);
for (int i = l+1 ; i <= r ; ++ i) {
if (jud(cir.r - (tmp[i] - cir.o).abs()) >= 0);
else {
cir = circle(tmp[i], 0);
for (int j = l ; j < i ; ++ j) {
if (jud(cir.r - (tmp[j] - cir.o).abs()) >= 0);
else {
cir = circle((tmp[i] + tmp[j]) * (0.5), (tmp[i] - tmp[j]).abs() * 0.5);
for (int k = l ; k < j ; ++ k) {
if (jud(cir.r - (tmp[k] - cir.o).abs()) >= 0);
else cir = circum(tmp[i], tmp[j], tmp[k]);
}
}
}
}
}
ans[cnt] = cir.o;
return jud(x - cir.r) >= 0;
}
bool doit(db x) {
cnt = 1;
for (int lp = 1, len ; lp <= n ; lp += len, ++ cnt) {
for (len = 1 ; lp + (len<<1) - 1 <= n && check(lp, lp + (len << 1) - 1, x) ; len <<= 1);
for (int i = (len >> 1) ; i >= 1 ; i >>= 1)
if (lp + len + i - 1 <= n && check(lp, lp + len + i - 1, x)) len += i;
check(lp, lp + len - 1, x);
}
-- cnt;
return cnt <= m;
}
int main() {
for (int i = 1, x, y ; i <= n ; ++ i) {
po[i] = point(x, y);
}
db l = 0, r = 2000000, mid;
while (r - l > 1e-8) {
mid = (l + r) / 2.0;
if (doit(mid)) r = mid;
else l = mid;
}
printf("%.7lf\n",r);
doit(r);
printf("%d\n",cnt);
for (int i = 1 ; i <= cnt ; ++ i)
printf("%.7lf %.7lf\n", ans[i].x, ans[i].y);
return 0;
}


posted @ 2018-12-30 11:04  莫名其妙的aaa  阅读(...)  评论(...编辑  收藏