牛客竞赛 1020 最大半径的圆
学习使用bitset , 记录所有和点相连的点
代码
#include<bits/stdc++.h>
using namespace std;
inline int read() {
int ans = 0, f = 1;
char ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-')f = -1;
ch = getchar();
}
while (ch <= '9' && ch >= '0') {
ans = ans * 10 + ch - '0';
ch = getchar();
}
return ans * f;
}
const int N = 3005;
double x[N],y[N];
bitset<N> p[N];
struct Item {
double dis;
int l,r;
bool operator<(const Item &x) const {
return dis > x.dis;
}
};
vector<Item> v;
double getdis(double x1,double y1,double x2,double y2) {
return (x1-x2) * (x1-x2) + (y1-y2) * (y1-y2);
}
int main() {
int n =read();
for (int i = 1; i<= n; i++) {
x[i]=read(),y[i]=read();
}
for (int i =1; i<= n; i++) {
for (int j = i+1;j<=n;j++) {
v.push_back({getdis(x[i],y[i],x[j],y[j]),i,j});
}
}
sort(v.begin(),v.end());
for (auto e : v) {
if ((p[e.l] & p[e.r]) !=0) {
cout<<fixed<<setprecision(8)<<sqrt(e.dis)/2.0<<"\n";
return 0;
}
p[e.l][e.r]= true;
p[e.r][e.l] = true;
}
return 0;
}