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): 5672    Accepted Submission(s): 2048


Problem Description
Robbie is playing an interesting computer game. The game field is an unbounded 2-dimensional region. There are N rounds in the game. At each round, the computer will give Robbie two places, and Robbie should choose one of them to put a bomb. The explosion area of the bomb is a circle whose center is just the chosen place. Robbie can control the power of the bomb, that is, he can control the radius of each circle. A strange requirement is that there should be no common area for any two circles. The final score is the minimum radius of all the N circles.
Robbie has cracked the game, and he has known all the candidate places of each round before the game starts. Now he wants to know the maximum score he can get with the optimal strategy.
 

Input
The first line of each test case is an integer N (2 <= N <= 100), indicating the number of rounds. Then N lines follow. The i-th line contains four integers x 1i, y 1i, x 2i, y 2i, indicating that the coordinates of the two candidate places of the i-th round are (x 1i, y 1i) and (x 2i, y 2i). All the coordinates are in the range [-10000, 10000].
 

Output
Output one float number for each test case, indicating the best possible score. The result should be rounded to two decimal places.
 

Sample Input
  
  
2 1 1 1 -1 -1 -1 -1 1 2 1 1 -1 -1 1 -1 -1 1
 

Sample Output
  
  
1.41 1.00
 

Source


2-SAT入门。


给你一些点对,要求从每对点当中选一个作圆,使得最后所有圆不相交。问所有圆的最小半径的最大值是多少。


二分圆的半径r,构图进行2-SAT。若两个点a,b的距离大于r,则说明它们不能被同时选择,连边a,b'、b,a'。

接下来就是根据2-SAT的判定规则进行判定,判定是否有一种选择方案满足所构建的图。


#include <cstdio>
#include <iostream>
#include <string.h>
#include <string> 
#include <map>
#include <queue>
#include <vector>
#include <set>
#include <algorithm>
#include <math.h>
#include <cmath>
#include <stack>
#define mem0(a) memset(a,0,sizeof(a))
#define meminf(a) memset(a,0x3f,sizeof(a))
using namespace std;
typedef long long ll;
typedef double db;
const int maxn=205,maxk=200005,inf=0x3f3f3f3f;  
const ll llinf=0x3f3f3f3f3f3f3f3f;   
const db pi=acos(-1.0),eps=1e-4;  
int x[maxn],y[maxn],head[maxn],color[maxn],dfn[maxn];
int num,cnt;

struct Edge {
	int from,to,pre;
};
Edge edge[maxk*2];

void addedge(int from,int to) {
	edge[num]=(Edge){from,to,head[from]};
	head[from]=num++;
}

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

db dis(int i,int j) {
	return sqrt(sqr(x[i]-x[j])+sqr(y[i]-y[j]));
}

void buildmap(int n,db mid) {
	int i,j;
	num=0;memset(head,-1,sizeof(head));
	for (i=0;i<n*2;i++) 
		for (j=i+1;j<n*2;j++) {
			if (i/2==j/2) continue;
			if (dis(i,j)<=mid)
				addedge(i,j^1),addedge(j,i^1);
		}
/*	cout << mid << endl;
	for (i=0;i<num;i++) {
		cout << edge[i].from << ' ' << edge[i].to << endl;
	}
	cout << '\n';*/
}

bool dfs(int now) {
	if (color[now]==1) return true;
	if (color[now]==2) return false;
	color[now]=1;color[now^1]=2;
	dfn[++cnt]=now;
	for (int i=head[now];i!=-1;i=edge[i].pre) {
		int to=edge[i].to;
		if (!dfs(to)) return false;
	}
	return true;
}

bool check(int n) {
	mem0(color);
	int i,j;
	for (i=0;i<n;i++) {
		if (!color[i*2]) {
			cnt=0;
			if (!dfs(i*2)) {
				for (j=1;j<=cnt;j++) color[dfn[j]]=color[dfn[j]^1]=0;
				if (!dfs(i*2+1)) return false;
			}
		}
	}
	return true;
}

int main() {
	int n;
	while (scanf("%d",&n)!=EOF) {
		int i;
		for (i=0;i<2*n;i++) 
			scanf("%d%d",&x[i],&y[i]);
		db l=1e-2,r=40000.0,ans=0.0,mid;
		while (fabs(r-l)>eps) {
			mid=(l+r)/2.0;
			buildmap(n,mid);
			if (check(n)) ans=mid,l=mid; else r=mid;
		}
		ans/=2.0;
		printf("%.2lf\n",ans);
	}
	return 0;
}



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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值