HDU2295-Radar

19 篇文章 0 订阅

Radar

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


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
 

Recommend
lcy
 

题意:有n个城市,m个雷达,k个操作员,每个操作员只能操作一个雷达。每个雷达的覆盖范围是一个以雷达坐标为中心的圆,所有雷达的覆盖半径是相同的。现在给出这n个城市,m个雷达的坐标,问雷达覆盖半径最小是多少,让所有城市都可以被雷达覆盖到

解题思路:二分+舞蹈链重复覆盖



#include <iostream>    
#include <cstdio>    
#include <cstring>    
#include <string>    
#include <algorithm>    
#include <cctype>    
#include <map>    
#include <cmath>    
#include <set>    
#include <stack>    
#include <queue>    
#include <vector>    
#include <bitset>    
#include <functional>    

using namespace std;

#define LL long long    
const int INF = 0x3f3f3f3f;
const int maxn = 300005;

int n, m, K, x[1009], y[1009];

struct DLX
{
	int L[maxn], R[maxn], U[maxn], D[maxn];
	int row[maxn], col[maxn], sum[maxn], ans[maxn];
	int n, m, num, cnt;
	int vis[maxn], flag[maxn];
	void add(int k, int l, int r, int u, int d, int x, int y)
	{
		L[k] = l;   R[k] = r;   U[k] = u;
		D[k] = d;   row[k] = x;  col[k] = y;
	}
	void reset(int n, int m)
	{
		this->n = n;   this->m = m;
		for (int i = 0; i <= m; i++)
		{
			add(i, i - 1, i + 1, i, i, 0, i);
			sum[i] = 0;
		}
		L[0] = m, R[m] = 0, cnt = m + 1;
	}
	void insert(int x, int y)
	{
		int temp = cnt - 1;
		if (row[temp] != x)
		{
			add(cnt, cnt, cnt, U[y], y, x, y);
			U[D[cnt]] = cnt; D[U[cnt]] = cnt;
		}
		else
		{
			add(cnt, temp, R[temp], U[y], y, x, y);
			R[L[cnt]] = cnt; L[R[cnt]] = cnt;
			U[D[cnt]] = cnt; D[U[cnt]] = cnt;
		}
		sum[y]++, cnt++;
	}
	void Remove(int k)
	{
		for (int i = D[k]; i != k; i = D[i])
		{
			L[R[i]] = L[i];
			R[L[i]] = R[i];
		}
	}
	void Resume(int k)
	{
		for (int i = U[k]; i != k; i = U[i]) L[R[i]] = R[L[i]] = i;
	}
	int A()
	{
		int dis = 0;
		for (int i = R[0]; i != 0; i = R[i]) vis[i] = 0;
		for (int i = R[0]; i != 0; i = R[i])
			if (!vis[i])
			{
				dis++, vis[i] = 1;
				for (int j = D[i]; j != i; j = D[j])
					for (int k = R[j]; k != j; k = R[k])
						vis[col[k]] = 1;
			}
		return dis;
	}
	void Dfs(int k)
	{
		if (!R[0]) num = min(num, k);
		else if (k + A() < num)
		{
			int now = R[0];
			for (int i = R[0]; i != 0; i = R[i])
				if (sum[now] > sum[i]) now = i;
			for (int i = D[now]; i != now; i = D[i])
			{
				Remove(i);
				for (int j = R[i]; j != i; j = R[j]) Remove(j);
				Dfs(k + 1);
				for (int j = L[i]; j != i; j = L[j]) Resume(j);
				Resume(i);
			}
		}
	}
	void mul()
	{
		memset(flag, 0, sizeof flag);
		num = 0x7FFFFFFF;
	}
}dlx;

int check(double k)
{
	dlx.reset(m, n);
	for (int i = 1; i <= m; i++)
		for (int j = 1; j <= n; j++)
		{
			double temp = (x[n + i] - x[j])*(x[n + i] - x[j]) + (y[n + i] - y[j])*(y[n + i] - y[j]);
			if (k - sqrt(temp) > 1e-8) dlx.insert(i, j);
		}
	dlx.mul();
	dlx.Dfs(0);
	if (dlx.num <= K) return 1;
	return 0;
}

int main()
{
	int t;
	scanf("%d", &t);
	while (t--)
	{
		scanf("%d%d%d", &n, &m, &K);
		for (int i = 1; i <= n + m; i++) scanf("%d%d", &x[i], &y[i]);
		double l = 0, r = 1500;
		while (r - l > 1e-8)
		{
			double mid = (l + r) / 2;
			if (check(mid)) r = mid;
			else l = mid;
		}
		printf("%.6f\n", r);
	}
	return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值