码迷,mamicode.com
首页 > 其他好文 > 详细

HDU 2295 Radar(DLX可重复覆盖)

时间:2014-12-25 01:30:48      阅读:460      评论:0      收藏:0      [点我收藏+]

标签:



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
 

Source
题意:n个城市,m个雷达站,最多用k个雷达站,问你每个雷达站的覆盖半径最少
为多少。DLX可重复覆盖做法:我们可以考虑以m个雷达站为N,以n个城市为M做成
DLX的可重复覆盖模型。那么N*M的bool值有如何确定了,我们考虑二分半径r,对
于每次二分的半径r,我们在根据距离求出bool矩阵的0和1,然后就是DLX的可重复
覆盖模型。值得注意由于最多不超过k个雷达站,也是重要剪枝。
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#include<string>
#include<iostream>
#include<queue>
#include<cmath>
#include<map>
#include<stack>
#include<bitset>
using namespace std;
#define REPF( i , a , b ) for ( int i = a ; i <= b ; ++ i )
#define REP( i , n ) for ( int i = 0 ; i < n ; ++ i )
#define CLEAR( a , x ) memset ( a , x , sizeof a )
typedef long long LL;
typedef pair<int,int>pil;
const int maxn = 55;
const int maxnnode=maxn*maxn;
const int mod = 1000000007;
const double eps=1e-8;
int K;
struct DLX{
    int n,m,size;
    int U[maxnnode],D[maxnnode],L[maxnnode],R[maxnnode],Row[maxnnode],Col[maxnnode];
    int H[maxn],S[maxn];//H[i]位置,S[i]个数
    int ansd,ans[maxn];
    void init(int a,int b)
    {
        n=a;  m=b;
        REPF(i,0,m)
        {
            S[i]=0;
            U[i]=D[i]=i;
            L[i]=i-1;
            R[i]=i+1;
        }
        R[m]=0; L[0]=m;
        size=m;
        REPF(i,1,n)
           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[maxnnode];
    int f()
    {
        int ret = 0;
        for(int c = R[0];c != 0;c = R[c])v[c] = true;
        for(int c = R[0];c != 0;c = R[c])
            if(v[c])
            {
                ret++;
                v[c] = false;
                for(int i = D[c];i != c;i = D[i])
                    for(int j = R[i];j != i;j = R[j])
                        v[Col[j]] = false;
            }
        return ret;

    }
    bool Dance(int d)
    {
        if(d + f() > K)return false;
        if(R[0] == 0)return d <= K;
        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 true;
            for(int j = L[i];j != i;j = L[j])resume(j);
            resume(i);
        }
        return false;
    }
};
struct point{
    int x,y;
}X[maxn],Y[maxn];
DLX L;
int T,N,M;
double dis(point a,point b)
{
    return sqrt((double)(a.x-b.x)*(a.x-b.x)+(double)(a.y-b.y)*(a.y-b.y));
}
void solve()
{
    double l=0,r=1e8;
    while(r-l>=eps)
    {
        double mid=(l+r)/2;
        L.init(M,N);
        for(int i=1;i<=M;i++)
        {
            for(int j=1;j<=N;j++)
            {
                if(dis(X[i],Y[j])<mid-eps)
                    L.link(i,j);
            }
        }
        if(L.Dance(0))  r=mid-eps;
        else   l=mid+eps;
    }
    printf("%.6lf\n",l);
}
int main()
{
    int x,y;
    scanf("%d",&T);
    while(T--)
    {
        scanf("%d%d%d",&N,&M,&K);
        REPF(i,1,N)
        {
            scanf("%d%d",&x,&y);
            Y[i].x=x;Y[i].y=y;
        }
        REPF(i,1,M)
        {
            scanf("%d%d",&x,&y);
            X[i].x=x;X[i].y=y;
        }
        solve();
    }
    return 0;
}


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
 

Source

HDU 2295 Radar(DLX可重复覆盖)

标签:

原文地址:http://blog.csdn.net/u013582254/article/details/42133491

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!