# BZOJ2663 [Beijing wc2012]灵魂宝石

### Solution

$k$的最大值可以二分图匹配：所有$\leqslant R$的可以构成一对。

### Code

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
const int N = 55;
int X[N], Y[N], x[N], y[N];
int n, K, R;
inline int sqr(int x) { return x * x; }
bool check(int i, int j, bool max) {
int l = sqr(X[i] - x[j]) + sqr(Y[i] - y[j]);
return max ? l >= R : l <= R;
}
int my[N];
bool vis[N];
bool dfs(int x, bool max) {
for (int y = 1; y <= n; ++y) if (!vis[y]) {
bool l = check(x, y, max);
if (!l) continue;
vis[y] = true;
if (!my[y] || dfs(my[y], max)) {
my[y] = x;
return true;
}
}
return false;
}
bool check(int mid, bool max) {
R = mid;
memset(my, 0, sizeof my);
int ans = 0;
for (int x = 1; x <= n; ++x) {
memset(vis, 0, sizeof vis);
if (dfs(x, max)) ++ans;
}
return max ? n - ans <= K : ans >= K;
}
int main() {
scanf("%d%d", &n, &K);
for (int i = 1; i <= n; ++i) scanf("%d%d", &X[i], &Y[i]);
for (int i = 1; i <= n; ++i) scanf("%d%d", &x[i], &y[i]);
int l = 0, r = 10000000;
while (l < r) {
int mid = (l + r) / 2;
if (check(mid, false)) r = mid;
else l = mid + 1;
}
printf("%.2lf ", sqrt(l));
if (K == n) { puts("+INF"); return 0; }
l = 0, r = 10000000;
while (l < r) {
int mid = r + (l - r) / 2;
if (check(mid, true)) l = mid;
else r = mid - 1;
}
printf("%.2lf\n", sqrt(l));
return 0;
}
posted @ 2018-03-06 08:28  _rqy  阅读(103)  评论(0编辑  收藏  举报