【DLX重复覆盖】HDU 2295 Radar

题意:一个国家有n个城市,有m个地方可以建造雷达,最多可以建K个雷达(K>=1 && K<=m),问雷达最短的探测半径,才能使n个城市都能探测到。
思路:比较裸一点的dl,二分答案,然后算出当前状况下 重复覆盖所需的雷达的个数,判断能否满足条件。
 
 
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>

using namespace std;

const double eps = 1e-8;
const int MAX_U = 3007;
const int MAX_N = 57;
const int MAX_M = 57;

int K;
struct DLX {
	int n, m, size;
	int U[MAX_U], D[MAX_U], R[MAX_U], L[MAX_U], Row[MAX_U], Col[MAX_U];
	int H[MAX_N], S[MAX_M];
	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 vis[MAX_M];
	int f() {
		int ret = 0;
		for (int c = R[0]; c != 0; c = R[c]) vis[c] = true;
		for (int c = R[0]; c != 0; c = R[c]) if(vis[c]) {
				ret++;
				vis[c] = false;
				for (int i = D[c]; i != c; i = D[i])
					for(int j = R[i]; j != i; j = R[j])
						vis[Col[j]] = false;
			}
		return ret;
	}
	bool dfs(int d) { 
		if(d + f() > K) return false;
		if(R[0] == 0) {
			return d <= K;
		}
		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);
			if (dfs(d + 1)) return true;
			for (int j = L[i]; j != i; j = L[j]) resume(j);
			resume(i);
		}
		return false;
	}
} dlx;  

struct Point {
	int x, y;
	Point() {
	}
	Point(int _x, int _y) {
		x = _x;
		y = _y;
	}
	void in() {
		scanf("%d%d", &x, &y);
	}
};

int n, m;
Point city[MAX_N], le[MAX_N];

int sqr(int x) {
	return x * x;
}

double dist(Point a, Point b) {
	return sqrt((double)sqr((a.x - b.x)) + (double)sqr((a.y - b.y)));
}

int main() {
	int T;
	scanf("%d", &T);
	while (T-- > 0) {
		scanf("%d%d%d", &n, &m, &K);
		for (int i = 0; i < n; ++i)
			city[i].in();
		for (int i = 0; i < m; ++i) 
			le[i].in();
		double l = 0, r = 1e8;
        while (l + eps < r) {
            double mid = (l + r) / 2;
            dlx.init(m, n);
            for (int i = 0; i < m; ++i)
                for (int j = 0; j < n; ++j)
                    if(dist(le[i], city[j]) < mid)
                        dlx.Link(i + 1, j + 1);
            if(dlx.dfs(0)) r = mid;
            else l = mid;
        }
        printf("%.6lf\n",l);
	}
	return 0;
}

  

 

转载于:https://www.cnblogs.com/Rojo/p/4626732.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值