HDU 3622 Bomb Game(2-sat)

HDU 3622 Bomb Game

题目链接

题意:求一个最大半径,使得每个二元组的点任选一个,可以得到所有圆两两不相交

思路:显然的二分半径,然后2-sat去判定即可

代码:

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

const int MAXNODE = 105;

struct TwoSet {
	int n;
	vector<int> g[MAXNODE * 2];
	bool mark[MAXNODE * 2];
	int S[MAXNODE * 2], sn;

	void init(int tot) {
		n = tot * 2;
		for (int i = 0; i < n; i += 2) {
			g[i].clear();
			g[i^1].clear();
		}
		memset(mark, false, sizeof(mark));
	}

	void add_Edge(int u, int uval, int v, int vval) {
		u = u * 2 + uval;
		v = v * 2 + vval;
		g[u^1].push_back(v);
		g[v^1].push_back(u);
	}

	void delete_Edge(int u, int uval, int v, int vval) {
		u = u * 2 + uval;
		v = v * 2 + vval;
		g[u^1].pop_back();
		g[v^1].pop_back();
	}

	bool dfs(int u) {
		if (mark[u^1]) return false;
		if (mark[u]) return true;
		mark[u] = true;
		S[sn++] = u;
		for (int i = 0; i < g[u].size(); i++) {
			int v = g[u][i];
			if (!dfs(v)) return false;
		}
		return true;
	}

	bool solve() {
		for (int i = 0; i < n; i += 2) {
			if (!mark[i] && !mark[i + 1]) {
				sn = 0;
				if (!dfs(i)){
					for (int j = 0; j < sn; j++)
						mark[S[j]] = false;
					sn = 0;
					if (!dfs(i + 1)) return false;
				}
			}
		}
		return true;
	}
} gao;

const int N = 105;
int n;

struct Point {
	double x, y;
	void read() {
		scanf("%lf%lf", &x, &y);
	}
} p[N][2];

inline double dis(Point a, Point b) {
	double dx = a.x - b.x;
	double dy = a.y - b.y;
	return sqrt(dx * dx + dy * dy);
}

inline bool xj(Point a, Point b, double r) {
	if (dis(a, b) > 2 * r) return false;
	return true;
}

bool judge(double r) {
	gao.init(n);
	for (int i = 0; i < n; i++) {
		for (int j = i + 1; j < n; j++) {
			for (int x = 0; x < 2; x++) {
				for (int y = 0; y < 2; y++) {
					if (xj(p[i][x], p[j][y], r))
						gao.add_Edge(i, x, j , y);
				}
			}
		}
	}
	return gao.solve();
}

int main() {
	while (~scanf("%d", &n)) {
		for (int i = 0; i < n; i++)
			for (int j = 0; j < 2; j++)
				p[i][j].read();
		double l = 0, r = 1e5;
		for (int i = 0; i < 30; i++) {
			double mid = (l + r) / 2;
			if (judge(mid)) l = mid;
			else r = mid;
		}
		printf("%.2lf\n", l);
	}
	return 0;
}
时间: 2024-11-05 23:34:06

HDU 3622 Bomb Game(2-sat)的相关文章

HDU 3622 Bomb Game(二分+2SAT)

题意:有一个游戏,有n个回合,每回合可以在指定的2个区域之一放炸弹,炸弹范围是一个圈,要求每回合的炸弹范围没有重合.得分是炸弹半径最小的值.求可以得到的最大分数. 思路:二分+2SAT. 二分炸弹范围,再根据有无重合建图,用2SAT判定. #include <cstdio> #include <cmath> #include <vector> #include <cstring> using namespace std; const int maxn =10

HDU 3622 Bomb Game(二分+2-SAT)

Bomb Game Time Limit: 10000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 5396    Accepted Submission(s): 1925 Problem Description Robbie is playing an interesting computer game. The game field is an unbounde

HDU 3622 Bomb Game (二分+2-SAT)

题目地址:HDU 3622 先二分半径,然后小于该半径的不能选,对这些不能选的点对进行加边.然后判断可行性即可. 代码如下: #include <iostream> #include <cstdio> #include <string> #include <cstring> #include <stdlib.h> #include <math.h> #include <ctype.h> #include <queue

HDU 3622 Bomb Game

Bomb Game Time Limit: 3000ms Memory Limit: 32768KB This problem will be judged on HDU. Original ID: 362264-bit integer IO format: %I64d      Java class name: Main Robbie is playing an interesting computer game. The game field is an unbounded 2-dimens

HDU - 3622 Bomb Game(二分+2-SAT)

题目大意:玩一个放炸弹游戏,有N次放炸弹的机会,每次放炸弹时,你都有两个位置可以选择,问如何放炸弹,能使爆炸的炸弹的半径的最小值最大(炸弹爆炸半径可以控制,但是爆炸形成的圈不能有重叠部分) 解题思路:最小值最大,二分 二分半径,如果有不满足的点,就建立起限制边,接着判断能否完成染色即可 #include <cstdio> #include <cstring> #include <algorithm> #include <cmath> #include <

HDOJ 3622 Bomb Game 2-sat

http://acm.hdu.edu.cn/showproblem.php?pid=3622 题意:上个月写的,题目好像是说一对点要选一个引爆,引爆半径自己选,任意两圆不能相交,最后分数是所有圆的最小半径,求最大分数. 分析:二分半径,2-sat判定可行性. 1 #include<cstdio> 2 #include<algorithm> 3 #include<cstring> 4 #include<cmath> 5 using namespace std;

hdu 3555 Bomb(数位dp)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3555 题目大意:就是给你一个数n,判断从0到n有多少个数含有数字49...... 是不是觉得跟hdu2089很相似呀... 思路:跟hdu2089一样的,注意给出的数比较大,所以这儿用__int64  .... code: #include<cstdio> #include<iostream> #include<cstring> #include<algorithm&

[ACM] hdu 3555 Bomb (数位DP,统计1-N中含有“49”的总数)

Bomb Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/65536 K (Java/Others) Total Submission(s): 7187 Accepted Submission(s): 2512 Problem Description The counter-terrorists found a time bomb in the dust. But this time the terrorists impro

HDU - 3555 Bomb (数位DP)

题意:求1-n里有多少人包含"49"的数字 思路:数位DP,分三种情况:到第i位没有49的情况,到第i位没有49且最高位是9的情况,到第i位有49的情况,将三种情况都考虑进去就是了 #include <iostream> #include <cstdio> #include <cstring> #include <algorithm> using namespace std; long long dp[30][3], n; int arr