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思路:要求所有城市都被覆盖的前提下,R最小。且用到的雷达要<=k。二分味很浓=_=。二分然后先判断是否所有城市都能被覆盖,能则求一次DLX重复覆盖。看需要的最少雷达的数目。不能覆盖或者雷达数目超过则要扩大半径。#include <stdio.h> #include <string.h> #include <iostream> #include <algorithm> #include <vector> #include <queue> #include <set> #include <map> #include <string> #include <math.h> #include <stdlib.h> #include <time.h> using namespace std; const int MaxM = 15*15+10; const int MaxN = 15*15+10; const int maxnode = MaxN * MaxM; const int INF = 0x3f3f3f3f; #define eps 1e-8 struct DLX { int n,m,size; int U[maxnode],D[maxnode],R[maxnode],L[maxnode],Row[maxnode],Col[maxnode]; int H[MaxN],S[MaxM]; int ansd; void init(int _n,int _m) { n = _n; m = _m; for(int i = 0;i <= m;i++) { S[i] = 0; U[i] = D[i] = i; L[i] = i-1; R[i] = i+1; } R[m] = 0; L[0] = m; size = m; for(int i = 1;i <= n;i++)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[MaxM]; 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; } void Dance(int d) { if(d + f() >= ansd)return; if(R[0] == 0) { if(d < ansd)ansd = d; return; } 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); Dance(d+1); for(int j = L[i];j != i;j = L[j])resume(j); resume(i); } } }; DLX g; double x[58],y[58],x2[58],y2[58]; bool vis[58]; int main() { //freopen("in.txt","r",stdin); int n,m,k,t; scanf("%d",&t); while(t--) { scanf("%d%d%d",&n,&m,&k); for(int i = 1;i <= n;i++) scanf("%lf%lf",&x[i],&y[i]); for(int i = 1;i <= m;i++) scanf("%lf%lf",&x2[i],&y2[i]); double l = 0,r = 2000; while(l+eps < r) { double mid = (l+r)/2; int num = 0; memset(vis,0,sizeof(vis)); g.init(m,n); for(int i = 1;i <= m;i++) { for(int j = 1;j <= n;j++) { if(((x2[i]-x[j])*(x2[i]-x[j])+(y2[i]-y[j])*(y2[i]-y[j])) <= mid*mid) { g.Link(i,j); if(!vis[j]) num++; vis[j] = 1; } } } if(num < n) l = mid; else { g.ansd = INF; g.Dance(0); if(g.ansd <= k) r = mid; else l = mid; } } printf("%.6lf\n",l); } }