二分爆炸半径,从第一个点开始 BFS,
这里用的double 储存坐标,相当于练一下浮点数二分了
其实再求两点间距离的时候可以不开根号,最后的时候开根号
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<vector>
#include<queue>
#include<set>
#include<stack>
#include<algorithm>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const int maxn = 1000 + 7, INF = 0x3f3f3f3f, mod = 1e9+7;
int T, tx, ty, n;
int vis[maxn];
struct node {
double x, y;
}a[maxn];
queue<node> qu;
node k;
void init() {
scanf("%lf%lf", &k.x, &k.y);
scanf("%d", &n);
for(int i = 0; i < n; ++i)
scanf("%lf%lf", &a[i].x, &a[i].y);
}
double dis(node a, node b) {
return sqrt((a.x-b.x)*(a.x-b.x) + (a.y-b.y)*(a.y-b.y));
}
bool bfs(double d) {
while(!qu.empty()) qu.pop();
qu.push(a[0]);
memset(vis, 0, sizeof vis); vis[0] = 1;
while(!qu.empty()) {
node t = qu.front(); qu.pop();
if(dis(t, k) <= d) return true;
for(int i = 1; i < n; ++i) {
if(!vis[i] && dis(t, a[i]) <= d) {
qu.push(a[i]), vis[i] = 1;
}
}
}
return false;
}
void solve() {
double l_ = 0.0, r_ = 10010000.0;
while(l_ < r_ - 0.0001 ) {
double mid = (l_ + r_) / 2.0;
if(bfs(mid)) r_ = mid;
else l_ = mid;
}
printf("%.2lf\n", r_);
}
int main() {
cin >> T;
while(T--) {
init();
solve();
}
return 0;
}