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

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

  1 /* ***********************************************
2 Author        :kuangbin
3 Created Time  :2014/5/26 22:20:05
4 File Name     :E:\2014ACM\专题学习\DLX\HDU2295.cpp
5 ************************************************ */
6
7 #include <stdio.h>
8 #include <string.h>
9 #include <iostream>
10 #include <algorithm>
11 #include <vector>
12 #include <queue>
13 #include <set>
14 #include <map>
15 #include <string>
16 #include <math.h>
17 #include <stdlib.h>
18 #include <time.h>
19 using namespace std;
20 const int maxnode = 3000;
21 const int MaxM = 55;
22 const int MaxN = 55;
23 int K;
24 struct DLX
25 {
26     int n,m,size;
27     int U[maxnode],D[maxnode],R[maxnode],L[maxnode],Row[maxnode],Col[maxnode];
28     int H[MaxN],S[MaxN];
29     int ands,ans[MaxN];
30     void init(int _n,int _m)
31     {
32         n = _n;
33         m = _m;
34         for(int i = 0;i <= m;i++)
35         {
36             S[i] = 0;
37             U[i] = D[i] = i;
38             L[i] = i-1;
39             R[i] = i+1;
40         }
41         R[m] = 0; L[0] = m;
42         size = m;
43         for(int i = 1;i <= n;i++)
44             H[i] = -1;
45     }
47     {
48         ++S[Col[++size]=c];
49         Row[size] = r;
50         D[size] = D[c];
51         U[D[c]] = size;
52         U[size] = c;
53         D[c] = size;
54         if(H[r] < 0)H[r] = L[size] = R[size] = size;
55         else
56         {
57             R[size] = R[H[r]];
58             L[R[H[r]]] = size;
59             L[size] = H[r];
60             R[H[r]] = size;
61         }
62     }
63     void remove(int c)
64     {
65         for(int i = D[c];i != c;i = D[i])
66             L[R[i]] = L[i], R[L[i]] = R[i];
67     }
68     void resume(int c)
69     {
70         for(int i = U[c];i != c;i = U[i])
71             L[R[i]]=R[L[i]]=i;
72     }
73     bool v[maxnode];
74     int f()
75     {
76         int ret = 0;
77         for(int c = R[0];c != 0;c = R[c])v[c] = true;
78         for(int c = R[0];c != 0;c = R[c])
79             if(v[c])
80             {
81                 ret++;
82                 v[c] = false;
83                 for(int i = D[c];i != c;i = D[i])
84                     for(int j = R[i];j != i;j = R[j])
85                         v[Col[j]] = false;
86             }
87         return ret;
88
89     }
90     bool Dance(int d)
91     {
92         if(d + f() > K)return false;
93         if(R[0] == 0)return d <= K;
94         int c = R[0];
95         for(int i = R[0];i != 0;i = R[i])
96             if(S[i] < S[c])
97                 c = i;
98         for(int i = D[c];i != c;i = D[i])
99         {
100             remove(i);
101             for(int j = R[i];j != i;j = R[j])remove(j);
102             if(Dance(d+1))return true;
103             for(int j = L[i];j != i;j = L[j])resume(j);
104             resume(i);
105         }
106         return false;
107     }
108 };
109 DLX g;
110 const double eps = 1e-8;
111 struct Point
112 {
113     int x,y;
114     void input()
115     {
116         scanf("%d%d",&x,&y);
117     }
118 }city[MaxM],station[MaxN];
119 double dis(Point a,Point b)
120 {
121     return sqrt((double)(a.x-b.x)*(a.x-b.x)+(double)(a.y-b.y)*(a.y-b.y));
122 }
123
124 int main()
125 {
126     //freopen("in.txt","r",stdin);
127     //freopen("out.txt","w",stdout);
128     int T;
129     int n,m;
130     scanf("%d",&T);
131     while(T--)
132     {
133         scanf("%d%d%d",&n,&m,&K);
134         for(int i = 0;i < n;i++)city[i].input();
135         for(int i = 0;i < m;i++)station[i].input();
136         double l = 0, r = 1e8;
137         while(r-l >= eps)
138         {
139             double mid = (l+r)/2;
140             g.init(m,n);
141             for(int i = 0;i < m;i++)
142                 for(int j = 0;j < n;j++)
143                     if(dis(station[i],city[j]) < mid - eps)
145             if(g.Dance(0))r = mid-eps;
146             else l = mid+eps;
147         }
148         printf("%.6lf\n",l);
149     }
150     return 0;
151 }

posted on 2014-05-27 17:35  kuangbin  阅读(3990)  评论(0编辑  收藏  举报

JAVASCRIPT: