题目来源:http://acm.hdu.edu.cn/showproblem.php?pid=2295
Radar
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1023 Accepted Submission(s): 405
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
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个雷达(K>=1 && K<=m),问雷达最短的探测半径,才能使n个城市都能探测到。思路:比较裸一点的Dancing Links,二分答案,然后算出当前状况下 重复覆盖所需的雷达的个数,判断能否满足条件。
对于这样的题 精度是比较恶心的,,我开始用1e-7,无论怎样二分都是wa,改成1e-8之后就能AC。。不过有的就是用1e-7过的。ORZ。。
4355580 | 2011-08-07 18:35:34 | Accepted | 2295 | 171MS | 228K | 2134 B | G++ | zyzamp |
4355579 | 2011-08-07 18:35:15 | Wrong Answer | 2295 | 171MS | 228K | 2134 B | G++ | zyzamp |
4355567 | 2011-08-07 18:32:46 | Wrong Answer | 2295 | 156MS | 228K | 2139 B | G++ | zyzamp |
4355553 | 2011-08-07 18:29:21 | Accepted | 2295 | 171MS | 228K | 2120 B | G++ | zyzamp |
4355527 | 2011-08-07 18:23:49 | Wrong Answer | 2295 | 31MS | 228K | 2055 B | G++ | zyzamp |
4355520 | 2011-08-07 18:21:54 | Accepted | 2295 | 375MS | 228K | 2084 B | G++ | zyzamp |
4355500 | 2011-08-07 18:13:43 | Wrong Answer | 2295 | 437MS | 228K | 2090 B | G++ | zyzamp |
4355498 | 2011-08-07 18:13:14 | Wrong Answer | 2295 | 406MS | 228K | 2090 B | G++ | zyzamp |
4355497 | 2011-08-07 18:13:03 | Compilation Error | 2295 | 0MS | 0K | 2090 B | C++ | zyzamp |
code:
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 Problem : 2295 ( Radar ) Judge Status : Accepted
2 RunId : 4355553 Language : G++ Author : zhuyawei
3 Code Render Status : Rendered By HDOJ G++ Code Render Version 0.01 Beta
4 # include<stdio.h>
5 # include<math.h>
6 # include<string.h>
7 # define eps 1e-8
8 # define N 55
9 # define V 3600
10 int n,m,K;
11 int L[V],R[V];
12 int D[V],U[V];
13 int C[V];
14 int S[N],H[N];
15 int ak,size;
16 double dis(double x1,double y1,double x2,double y2)
17 {
18 return sqrt((x2-x1)*(x2-x1) + (y2-y1)*(y2-y1));
19 }
20 void Link(int r,int c)
21 {
22 S[c]++;C[size]=c;
23 U[size]=U[c];D[U[c]]=size;
24 D[size]=c;U[c]=size;
25 if(H[r]==-1) H[r]=L[size]=R[size]=size;
26 else
27 {
28 L[size]=L[H[r]];R[L[H[r]]]=size;
29 R[size]=H[r];L[H[r]]=size;
30 }
31 size++;
32 }
33 void remove(int c)
34 {
35 int i;
36 for(i=D[c];i!=c;i=D[i])
37 L[R[i]]=L[i],R[L[i]]=R[i];
38 }
39 void resume(int c)
40 {
41 int i;
42 for(i=U[c];i!=c;i=U[i])
43 L[R[i]]=R[L[i]]=i;
44 }
45 int h()
46 {
47 int i,j,k,count=0;
48 bool visit[N];
49 memset(visit,0,sizeof(visit));
50 for(i=R[0];i;i=R[i])
51 {
52 if(visit[i]) continue;
53 count++;
54 visit[i]=1;
55 for(j=D[i];j!=i;j=D[j])
56 {
57 for(k=R[j];k!=j;k=R[k])
58 visit[C[k]]=1;
59 }
60 }
61 return count;
62 }
63 void Dance(int k)
64 {
65 int i,j,c,Min,ans;
66 ans=h();
67 if(k+ans>K || k+ans>=ak) return;
68 if(!R[0])
69 {
70 if(k<ak) ak=k;
71 return;
72 }
73 for(Min=N,i=R[0];i;i=R[i])
74 if(S[i]<Min) Min=S[i],c=i;
75 for(i=D[c];i!=c;i=D[i])
76 {
77 remove(i);
78 for(j=R[i];j!=i;j=R[j])
79 remove(j);
80 Dance(k+1);
81 for(j=L[i];j!=i;j=L[j])
82 resume(j);
83 resume(i);
84 }
85 return;
86 }
87 int main()
88 {
89 int i,j,ncase;
90 double x[N],y[N],x1[N],y1[N];
91 double left,right,ans,mid;
92 scanf("%d",&ncase);
93 while(ncase--)
94 {
95 scanf("%d%d%d",&n,&m,&K);
96 for(i=1;i<=n;i++)
97 scanf("%lf%lf",&x[i],&y[i]);
98 for(i=1;i<=m;i++)
99 scanf("%lf%lf",&x1[i],&y1[i]);
100 left=0;
101 right=1416.0;
102 ans=right;
103 while(right>=left)
104 {
105 for(i=0;i<=n;i++)
106 {
107 S[i]=0;
108 U[i]=D[i]=i;
109 L[i+1]=i;R[i]=i+1;
110 }R[n]=0;
111 memset(H,-1,sizeof(H));
112 size=n+1;
113 mid=(left+right)/2;
114 for(i=1;i<=m;i++)
115 {
116 for(j=1;j<=n;j++)
117 if(mid>=dis(x1[i],y1[i],x[j],y[j])) Link(i,j);
118 }
119 ak=N;
120 Dance(0);
121 if(ak<=K) {ans=mid<ans?mid:ans;right=mid-eps;}
122 else left=mid+eps;
123 }
124 printf("%.6lf\n",ans);
125 }
126 return 0;
127 }