【HDU 3622】Bomb Game

http://acm.hdu.edu.cn/showproblem.php?pid=3622
二分答案转化成2-sat问题。
上午测试时总想二分后把它转化成最大点独立集但是不会写最大点独立集暴力又秘制写错所以就爆零啦~~~

#include<cmath>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;

const int N = 503;

double x[N << 1], y[N << 1], dis[N << 1][N << 1];
double sqr(double x) {return x * x;}

struct node {int nxt, to;} E[N * N];
int bel[N << 1], dfn[N << 1], low[N << 1], dfn_cnt;
int st[N << 1], top = 0, cnt, point[N << 1], dn, n, col_tot;
bool inst[N << 1];

void ins(int u, int v) {E[++cnt] = (node) {point[u], v}; point[u] = cnt;}

void tarjan(int u) {
	dfn[u] = low[u] = ++dfn_cnt;
	inst[st[++top] = u] = true;
	if (u == 11) {
		++u; --u;
	}
	for (int i = point[u]; i; i = E[i].nxt) {
		if (!dfn[E[i].to]) tarjan(E[i].to), low[u] = min(low[u], low[E[i].to]);
		else if (inst[E[i].to]) low[u] = min(low[u], dfn[E[i].to]);
	}
	if (dfn[u] == low[u]) {
		++col_tot;
		while (st[top] != u) {
			inst[st[top]] = false;
			bel[st[top--]] = col_tot;
		}
		inst[u] = false; bel[u] = col_tot; --top;
	}
}

bool can(double num) {
	cnt = 0;
	memset(point, 0, sizeof(int) * dn);
	for (int i = 0; i < dn; ++i)
		for (int j = i + 1; j < dn; ++j)
			if (j - i != n && dis[i][j] < num)
				ins(i, (j + n) % dn), ins(j, (i + n) % dn);
	
	dfn_cnt = col_tot = 0;
	memset(dfn, 0, sizeof(int) * dn);
	for (int i = 0; i < dn; ++i)
		if (dfn[i] == 0) tarjan(i);
	
	for (int i = 0; i < n; ++i)
		if (bel[i] == bel[i + n])
			return false;
	return true;
}

int main() {
	while (~scanf("%d", &n)) {
		for (int i = 0; i < n; ++i)
			scanf("%lf%lf%lf%lf", x + i, y + i, x + n + i, y + n + i);
		
		dn = n << 1;
		for (int i = 0; i < dn; ++i)
			for (int j = i + 1; j < dn; ++j)
				if (j - i != n)
					dis[i][j] = dis[j][i] = sqrt(sqr(x[i] - x[j]) + sqr(y[i] - y[j]));
		
		double left = 0, right = 22000, mid;
		while (right - left > 1e-5) {
			mid = (left + right) / 2;
			if (can(mid)) left = mid;
			else right = mid;
		}
		printf("%.2lf\n", left / 2);
	}
	return 0;
}
posted @ 2017-01-21 15:34  abclzr  阅读(245)  评论(0编辑  收藏  举报