思路:裸的DLX重复覆盖

#include<set>
#include<cmath>
#include<queue>
#include<cstdio>
#include<vector>
#include<string>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#define pb push_back
#define mp make_pair
#define Maxn 51
#define Maxm 80002
#define LL __int64
#define Abs(x) ((x)>0?(x):(-x))
#define lson(x) (x<<1)
#define rson(x) (x<<1|1)
#define inf 1000000
#define lowbit(x) (x&(-x))
#define clr(x,y) memset(x,y,sizeof(x))
#define Mod 1000000007
using namespace std;
int D[Maxn*Maxn],U[Maxn*Maxn],L[Maxn*Maxn],R[Maxn*Maxn],S[Maxn*Maxn],C[Maxn*Maxn],H[Maxn],id,K,n,m,cnt;
bool vi[Maxn];
struct Point{
double x,y;
}city[Maxn],rader[Maxn];
double dis[Maxn][Maxn],edge[Maxn*Maxn];
double Dis(Point a,Point b)
{
return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
}
void init(int m)
{
int i;
for(i=;i<=m;i++){
D[i]=U[i]=i;
L[i+]=i;
R[i]=i+;
S[i]=;
}
R[m]=;
id=m+;
}
void ins(int r, int c)
{
U[id] = c;
D[id] = D[c];
U[D[c]] = id;
D[c] = id;
if (H[r] < )
H[r] = L[id] = R[id] = id;
else
{
L[id] = H[r];
R[id] = R[H[r]];
L[R[H[r]]] = id;
R[H[r]] = id;
}
S[c]++;
C[id++] = c;
}
void Remove(int c)
{
int i;
for(i=D[c];i!=c;i=D[i]){
L[R[i]]=L[i];
R[L[i]]=R[i];
}
}
void Resume(int c)
{
int i;
for(i=D[c];i!=c;i=D[i]){
L[R[i]]=i;
R[L[i]]=i;
}
}
int A()
{
int i,j,k,ret=;
memset(vi,false,sizeof(vi));
for(i=R[];i;i=R[i]) if(!vi[i]){
ret++;
for(j=D[i];j!=i;j=D[j]){
for(k=R[j];k!=j;k=R[k])
vi[C[k]]=true;
}
}
return ret;
}
int dfs(int step)
{
if(step+A()>K) return false;
if(R[]==) return true;
int i,j,temp,c;
temp=inf;
for(i=R[];i;i=R[i]) if(S[i]<temp){
temp=S[i];
c=i;
}
for(i=D[c];i!=c;i=D[i]){
Remove(i);
for(j=R[i];j!=i;j=R[j]){
Remove(j);
}
if(dfs(step+))
return true;
for(j=R[i];j!=i;j=R[j])
Resume(j);
Resume(i);
}
return false;
}
void build(int pos)
{
int i,j;
init(n);
for(i=;i<=m;i++){
H[i]=-;
for(j=;j<=n;j++){
if(dis[i][j]<=edge[pos])
ins(i,j);
}
}
}
void solve()
{
int i,j,l,r,mid;
l=,r=cnt;
while(l<r){
mid=(l+r)>>;
build(mid);
if(dfs())
r=mid;
else
l=mid+;
}
printf("%.6lf\n",edge[l]);
}
int main()
{
int t,i,j;
scanf("%d",&t);
while(t--){
scanf("%d%d%d",&n,&m,&K);
for(i=;i<=n;i++)
scanf("%lf%lf",&city[i].x,&city[i].y);
for(i=;i<=m;i++)
scanf("%lf%lf",&rader[i].x,&rader[i].y);
cnt=;
for(i=;i<=m;i++)
for(j=;j<=n;j++){
dis[i][j]=Dis(rader[i],city[j]);
edge[++cnt]=dis[i][j];
}
sort(edge+,edge++cnt);
int num=;
for(i=;i<=cnt;i++) if(edge[i]!=edge[num]){
edge[++num]=edge[i];
}
cnt=num;
solve();
}
return ;
}
05-11 11:15