hdu 2295 Radar(Dancing Links重复覆盖)

Radar

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 2903    Accepted Submission(s): 1124


Problem Description
N cities of the Java Kingdom need to be covered by radars for being in a state of war. Since the kingdom has M radar stations but only K operators, we can at most operate K radars. All radars have the same circular coverage with a radius of R. Our goal is to minimize R while covering the entire city with no more than K radars.
 

Input
The input consists of several test cases. The first line of the input consists of an integer T, indicating the number of test cases. The first line of each test case consists of 3 integers: N, M, K, representing the number of cities, the number of radar stations and the number of operators. Each of the following N lines consists of the coordinate of a city.
Each of the last M lines consists of the coordinate of a radar station.

All coordinates are separated by one space.
Technical Specification

1. 1 ≤ T ≤ 20
2. 1 ≤ N, M ≤ 50
3. 1 ≤ K ≤ M
4. 0 ≤ X, Y ≤ 1000
 

Output
For each test case, output the radius on a single line, rounded to six fractional digits.
 

Sample Input
  
  
1 3 3 2 3 4 3 1 5 4 1 1 2 2 3 3
 

Sample Output
  
  
2.236068
 

n个城市 m个雷达 现在最多使用K个雷达覆盖所有的城市 求出雷达覆盖半径的最小值


二分距离 然后求出当前情况下 使用雷达最少的数量 如果符合要求 那就缩小当前距离 如果不符合就扩大

DancingLinks 感觉重复覆盖建图 比精确覆盖要难。。。

#include <cstdio>
#include <iostream>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <string.h>
#include <string>
#include <vector>
#include <queue>

#define MEM(a,x) memset(a,x,sizeof a)
#define eps 1e-8
#define MOD 10009
#define INF 99999999
#define ll __int64
#define bug cout<<"here"<<endl
#define fread freopen("ceshi.txt","r",stdin)
#define fwrite freopen("out.txt","w",stdout)

using namespace std;

const int MAXM=60;
const int MAXN=60;
const int maxnode=MAXN*MAXM;

int K;
struct DLX
{
    int n,m,size;
    int U[maxnode],D[maxnode],R[maxnode],L[maxnode],Row[maxnode],Col[maxnode];
    int H[MAXN],S[MAXM];
    int ansd;
    void init(int _n,int _m)
    {
        n=_n; m=_m;
        for(int i=0;i<=m;i++)
        {
            S[i]=0;
            U[i]=D[i]=i;
            L[i]=i-1;
            R[i]=i+1;
        }
        R[m]=0; L[0]=m;
        size=m;
        for(int i=1;i<=n;i++) H[i]=-1;
    }
    void Link(int r,int c)
    {
        ++S[Col[++size]=c];
        Row[size]=r;
        D[size]=D[c];
        U[D[c]]=size;
        U[size]=c;
        D[c]=size;
        if(H[r]<0) H[r]=L[size]=R[size]=size;
        else
        {
            R[size]=R[H[r]];
            L[R[H[r]]]=size;
            L[size]=H[r];
            R[H[r]]=size;
        }
    }
    void remove(int c)
    {
        for(int i=D[c];i!=c;i=D[i])
            L[R[i]]=L[i], R[L[i]]=R[i];
    }
    void resume(int c)
    {
        for(int i=U[c];i!=c;i=U[i])
            L[R[i]]=R[L[i]]=i;
    }
    bool v[MAXM];
    int f()
    {
        int ret=0;
        for(int c=R[0];c!=0;c=R[c]) v[c]=1;
        for(int c=R[0];c!=0;c=R[c])
        {
            if(v[c])
            {
                ret++;
                v[c]=0;
                for(int i=D[c];i!=c;i=D[i])
                    for(int j=R[i];j!=i;j=R[j])
                        v[Col[j]]=0;
            }
        }
        return ret;
    }
    bool Dance(int d)
    {
//        cout<<d<<endl;
        if(d+f()>K) return 0;//个数大于K 不符合要求
        if(R[0]==0)
        {
            if(d<=K) return 1;
            else return 0;
        }
        int c=R[0];
        for(int i=R[0];i!=0;i=R[i])
            if(S[i]<S[c])
                c=i;
        for(int i=D[c];i!=c;i=D[i])
        {
            remove(i);
            for(int j=R[i];j!=i;j=R[j]) remove(j);
            if(Dance(d+1)) return 1;
            for(int j=L[i];j!=i;j=L[j]) resume(j);
            resume(i);
        }
        return 0;
    }
};
DLX dlx;
int x[60],y[60],xx[60],yy[60];
double dis(int a,int b,int c,int d)
{
    double len=(double)((c-a)*(c-a)+(d-b)*(d-b));
    return sqrt(len);
}

int main()
{
//    fread;
    int tc;
    scanf("%d",&tc);
    while(tc--)
    {
        int n,m;
        scanf("%d%d%d",&n,&m,&K);
        for(int i=0;i<n;i++)
            scanf("%d%d",&x[i],&y[i]);
        for(int i=0;i<m;i++)
            scanf("%d%d",&xx[i],&yy[i]);
        double left=0.0,right=1500.0,mid;
        while(right-left>eps)
        {
//            bug;
            dlx.init(m,n);
            mid=(left+right)/2.0;
            for(int i=0;i<m;i++)
                for(int j=0;j<n;j++)
            {
                if(mid-eps>(dis(xx[i],yy[i],x[j],y[j])))
                    dlx.Link(i+1,j+1);
            }
            if(dlx.Dance(0)) right=mid-eps;
            else left=mid+eps;
        }
        printf("%.6lf\n",right);
    }
    return 0;
}






  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值