CF333E Summer Earnings

一、题目

点此看题

二、解法

一道巧用 b i t s e t bitset 的题,如果要用 b i t s e t bitset 优化,那么可能就是把关键问题转化为 01 01 运算。

从大到小枚举两点之间的距离当做答案(当做边),我们要看是否有一个点满足到这两个点的距离不小于这个距离,把以前枚举的边构建一个邻接矩阵,那么我们要看 u u 行和 v v 行是否有同为 1 1 的,就可以用 b i t s e t bitset 判断。

#include <cstdio>
#include <bitset>
#include <algorithm>
#include <cmath>
using namespace std;
const int M = 3005;
int read()
{
	int x=0,f=1;char c;
	while((c=getchar())<'0' || c>'9') {if(c=='-') f=-1;}
	while(c>='0' && c<='9') {x=(x<<3)+(x<<1)+(c^48);c=getchar();}
	return x*f;
}
int n,m,ans,x[M],y[M];
bitset<M> bit[M];
struct node
{
	int u,v,d;
	bool operator < (const node &b) const
	{
		return d<b.d;
	}
}a[M*M];
int cal(int i,int j)
{
	return (x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j]);
}
signed main()
{
	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++)
			a[++m]=node{i,j,cal(i,j)};
	sort(a+1,a+1+m);
	for(int i=m;i>=1;i--)
	{
		int u=a[i].u,v=a[i].v;
		bitset<M> t=bit[u]&bit[v];
		if(t.any()) ans=max(ans,a[i].d);
		bit[u][v]=bit[v][u]=1;
	}
	printf("%.6lf\n",sqrt(ans/4.0));
}

猜你喜欢

转载自blog.csdn.net/C202044zxy/article/details/107561897