[SDOI2012]拯救小云公主
Posted kma093
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了[SDOI2012]拯救小云公主相关的知识,希望对你有一定的参考价值。
题目链接:
分析
最大的最小最小的最大 一看就非常的二分
考虑二分之后转化成判定联通问题
于是可以考虑奶酪
直接维护联通好像很\\(GG\\),正难则反考虑维护不连通
什么时候不连通,发现当左上角和右下角分在两个块里面就凉了
当上和右边或上和下边联通的时候左上角和右下角被分割在两块
另外两种情况同理
于是并查集仿照奶酪维护一下,如果四种都没联通说明可以走到
外面再套个二分 复杂度\\(O(n ^ 2 * log(n))\\) 此代码吸氧可过
#include<bits/stdc++.h>
#define eps 1e-8
#define N (3000 + 10)
using namespace std;
inline int read()
int cnt = 0, f = 1; char c = getchar();
while (!isdigit(c)) if (c == '-') f = -f; c = getchar();
while (isdigit(c)) cnt = (cnt << 3) + (cnt << 1) + (c ^ 48); c = getchar();
return cnt * f;
int n, R, L, fa[N];
double ans;
struct node
double x, y;
a[N];
int get_fa(int x) return x == fa[x] ? x : fa[x] = get_fa(fa[fa[fa[fa[x]]]]);
double Pow(double x) return x * x;
bool dis(node a, node b, double r)
return (r * r * 4 - Pow(a.x - b.x) - Pow(a.y - b.y)) > 0;
bool check(double r)
for (register int i = 1; i <= n + 2; ++i) fa[i] = i;
for (register int i = 1; i <= n; ++i)
if (a[i].x - r <= 1 || a[i].y + r >= L) fa[i] = n + 1;
if (a[i].x + r >= R || a[i].y - r <= 1) fa[get_fa(i)] = n + 2;
for (register int i = 1; i <= n; ++i)
for (register int j = i; j <= n; ++j)
int fx = get_fa(i), fy = get_fa(j);
if (fx == fy) continue;
if (!dis(a[i], a[j], r)) continue;
fa[fx] = fy;
if (get_fa(n + 1) == get_fa(n + 2)) return false;
if (get_fa(n + 1) == get_fa(n + 2)) return false;
return true;
inline double binary()
double l = 0, r = min(L, R);
double mid = (l + r) / 2.0;
while (r - l > eps)
// cout<<l<<" "<<r<<endl;
if (check(mid)) l = mid;
else r = mid;
mid = (l + r) / 2.0;
return mid;
int main()
// freopen("1.in", "r", stdin);
// freopen("own.out", "w", stdout);
n = read(), R = read(), L = read();
for (register int i = 1; i <= n; ++i) a[i].x = read(), a[i].y = read();
ans = binary();
printf("%.2lf", ans);
return 0;
以上是关于[SDOI2012]拯救小云公主的主要内容,如果未能解决你的问题,请参考以下文章