搜索(DLX重复覆盖模板):HDU 2295 Radar

 

Radar

 

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


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
  水题,主要是为了贴模板。
  1 #include <iostream>
  2 #include <cstring>
  3 #include <cstdio>
  4 #include <cmath>
  5 using namespace std;
  6 const double eps=1e-8;
  7 const int N=55,M=3005;
  8 struct Point{int x,y;}c[N],r[N];
  9 double sqr(double x){return 1.0*x*x;}
 10 double dis(Point a,Point b){return sqrt(sqr(a.x-b.x)+sqr(a.y-b.y));}
 11 
 12 void P(int x){
 13   printf("%d\n",x);
 14 }
 15 
 16 int T,n,m,k,col[M],row[M];
 17 int U[M],D[M],L[M],R[M];
 18 int H[N],C[N],vis[N],cnt;
 19 struct DLX{
 20   void Init(int n,int m){
 21     for(int i=0;i<=m;i++){
 22       L[i]=i-1;R[i]=i+1;
 23       C[i]=0;U[i]=D[i]=i;
 24     }L[0]=m;R[m]=0;cnt=m;
 25     for(int i=1;i<=n;i++)H[i]=0;
 26   }
 27   void Link(int r,int c){
 28     C[c]+=1;++cnt;
 29     U[D[c]]=cnt;U[cnt]=c;
 30     D[cnt]=D[c];D[c]=cnt;
 31     row[cnt]=r;col[cnt]=c;
 32     
 33     if(H[r]){
 34       L[R[H[r]]]=cnt;L[cnt]=H[r];
 35       R[cnt]=R[H[r]];R[H[r]]=cnt;
 36     }
 37     else H[r]=L[cnt]=R[cnt]=cnt;
 38   }
 39   void Delete(int x){
 40     for(int i=D[x];i!=x;i=D[i])
 41       L[R[i]]=L[i],R[L[i]]=R[i];
 42   }
 43   void Resume(int x){
 44     for(int i=U[x];i!=x;i=U[i])
 45       L[R[i]]=i,R[L[i]]=i;
 46   }
 47   int F(){
 48     int ret=0;
 49     for(int c=R[0];c;c=R[c])vis[c]=0;
 50     for(int c=R[0];c;c=R[c]){
 51       if(vis[c])continue;ret+=1;
 52       for(int i=D[c];i!=c;i=D[i])
 53     for(int j=R[i];j!=i;j=R[j])
 54       vis[col[j]]=1;vis[c]=1;
 55     }
 56     return ret;
 57   }
 58   bool Dance(int dep){
 59     if(!R[0])return dep<=k;
 60     if(dep+F()>k)return false;
 61     int p=0;
 62     for(int i=R[0];i;i=R[i])
 63       if(!p||C[i]<C[p])p=i;
 64     for(int i=D[p];i!=p;i=D[i]){
 65       Delete(i);
 66       for(int j=R[i];j!=i;j=R[j])Delete(j);
 67       if(Dance(dep+1))return true;
 68       for(int j=L[i];j!=i;j=L[j])Resume(j);
 69       Resume(i);
 70     }
 71     return false;
 72   }
 73 
 74   bool Check(double d){
 75     Init(m,n);
 76     for(int i=1;i<=m;i++)
 77       for(int j=1;j<=n;j++)
 78     if(d>=dis(r[i],c[j]))
 79       Link(i,j);
 80     return Dance(0);
 81   }
 82 }dlx;
 83 
 84 int main(){
 85   scanf("%d",&T);
 86   while(T--){
 87     scanf("%d%d%d",&n,&m,&k);
 88     for(int i=1;i<=n;i++)
 89       scanf("%d%d",&c[i].x,&c[i].y);
 90     for(int i=1;i<=m;i++)
 91       scanf("%d%d",&r[i].x,&r[i].y);
 92     double l=0,r=1e3;
 93     while(r-l>=eps){
 94       double mid=(l+r)/2;
 95       if(dlx.Check(mid))r=mid;
 96       else l=mid;
 97     }
 98     printf("%.6f\n",l);
 99   }
100   return 0;
101 }

 

posted @ 2016-11-14 18:49  TenderRun  阅读(443)  评论(0编辑  收藏  举报