HDU 3585 Maximum Shortest Distance 最大团 二分答案

33 篇文章 0 订阅
21 篇文章 0 订阅

%%% http://www.cnblogs.com/zhj5chengfeng/archive/2013/07/29/3224092.html

平面上有N个点,确定k个点使其中各点对距离的最小值最大。有多组数据。

这个最优化问题本身似乎不好解决,所以还是二分一下吧。。

如果已知距离的最小值mid,判定是否存在k个点且两两距离均超过mid。

将距离超过mid的点连起来求一下最大团即可。


二分的时候跪了。。

判断二分结束的条件r - l > 1e-4,写1e-3就WA了。。

这个故事告诉我们不要吝啬。。开够保证正确性为好。。

人生第一次vim & g++ & gdb 全成就达成。

#include <cstdio>
using namespace std;

const int N = 65;
int ans, f[N], set[N][N], a[N][N];

bool dfs(int sz, int dep) {
	if (!sz) 
		if (dep > ans) return ans = dep, 1;
		else return 0;

	for (int i = 1; i <= sz; i++) {
		if (dep + sz - i + 1 <= ans) return 0;
		int u = set[dep][i];
		if (dep + f[u] <= ans) return 0;
		int num = 0;
		for (int j = i + 1; j <= sz; j++)
			if (a[u][set[dep][j]])
				set[dep + 1][++num] = set[dep][j];
		if (dfs(num, dep + 1)) return 1;
	}
	return 0;
}

struct Point {
	double x, y;
	friend double dis(const Point &a, const Point &b) {
		return (a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y);
	}
} p[N];

int main() {
	int n, m, i, j, sz;
	while (scanf("%d%d", &n, &m) == 2) {
		for (i = 1; i <= n; i++)
			scanf("%lf%lf", &p[i].x, &p[i].y);
		double l = 0, r = 20000;
		while (r - l > 1e-4) {
			double mid = (l + r) / 2;
			ans = 0;
			for (i = 1; i < n; i++)
				for (j = i + 1; j <= n; j++)
					a[i][j] = a[j][i] = (dis(p[i], p[j]) >= mid * mid);
			for (i = n; i; i--) {
				sz = 0;
				for (j = i + 1; j <= n; j++)
					if (a[i][j])
						set[1][++sz] = j;
				dfs(sz, 1);
				f[i] = ans;
			}
			if (ans >= m) l = mid;
			else r = mid;
		}
		printf("%.2lf\n", l);
	}

	return 0;
}


maximum shortest distance

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


Problem Description
There are n points in the plane. Your task is to pick k points (k>=2), and make the closest points in these k points as far as possible.
 

Input
For each case, the first line contains two integers n and k. The following n lines represent n points. Each contains two integers x and y. 2<=n<=50, 2<=k<=n, 0<=x,y<10000.
 

Output
For each case, output a line contains a real number with precision up to two decimal places.

 

Sample Input
  
  
3 2 0 0 10 0 0 20
 

Sample Output
  
  
22.36

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值