hdu 5046 Airport(Dancing Links重复覆盖)

Airport

Time Limit: 3000/1500 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 1310    Accepted Submission(s): 405


Problem Description
The country of jiuye composed by N cites. Each city can be viewed as a point in a two- dimensional plane with integer coordinates (x,y). The distance between city i and city j is defined by d ij = |x i - x j| + |y i - y j|. jiuye want to setup airport in K cities among N cities. So he need your help to choose these K cities, to minimize the maximum distance to the nearest airport of each city. That is , if we define d i(1 ≤ i ≤ N ) as the distance from city i to the nearest city with airport. Your aim is to minimize the value max{d i|1 ≤ i ≤ N }. You just output the minimum.
 

Input
The first line of the input is T (1 ≤ T ≤ 100), which stands for the number of test cases you need to solve.

The first line of each case contains two integers N ,K (1 ≤ N ≤ 60,1 ≤ K ≤ N ),as mentioned above.

The next N lines, each lines contains two integer x i and y i (-10 9 ≤ x i, y i ≤ 10 9), denote the coordinates of city i.
 

Output
For each test case, print a line “Case #t: ”(without quotes, t means the index of the test case) at the beginning. Then a single integer means the minimum.
 

Sample Input
 
   
2 3 2 0 0 4 0 5 1 4 2 0 3 1 0 3 0 8 9
 

Sample Output
 
   
Case #1: 2 Case #2: 4
 

n个城市  找出k个城市建立机场 每个城市与距离自己最近的机场之间有距离 

求出这些距离中最大值的最小值


与hdu 2295十分类似 只是距离的表达方式不同 

同样二分距离 如果两个城市之间的距离小于二分的值就建边 跑Dancing Links重复覆盖 

#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 

#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"<K) return 0;
        if(R[0]==0)
        {
            return d<=K;
        }
        int c=R[0];
        for(int i=R[0];i!=0;i=R[i])
            if(S[i]b) return a-b;
    return b-a;
}

ll dis(City a,City b)
{
    return ABS(a.x,b.x)+ABS(a.y,b.y);
}

int main()
{
//    fread;
    int tc;
    scanf("%d",&tc);
    int cs=1;
    while(tc--)
    {
        int n;
        scanf("%d%d",&n,&K);
        for(int i=1;i<=n;i++)
            city[i].input();
//        for(int i=1;i<=n;i++)
//            cout<0)
        {
            mid=(r+l)/2;
            dlx.init(n,n);
            for(int i=1;i<=n;i++)
                for(int j=1;j<=n;j++)
                {
                    if(dis(city[i],city[j])<=mid)
                    {
                        dlx.Link(i,j);
                    }
                }
            if(dlx.Dance(0)) r=mid,ans=mid;
            else l=mid+1;
        }
        printf("Case #%d: %I64d\n",cs++,r);
    }
    return 0;
}






你可能感兴趣的:(Dancing,Links)