[HDOJ 3622][Vjudge 11707] Bomb Game [2-SAT+二分答案]

69 篇文章 0 订阅
8 篇文章 0 订阅

给n组点,每组2个,在每组中选取一个作为圆心,做一些圆,要求圆与圆不能相交,问这些圆中的最小半径的最大值为多少

假设所有圆均为等半径,二分答案,2-SAT判断是否有可行解

#include <cstring>
#include <cstdio>
#include <cmath>

bool canPut(int x1,int y1,int x2,int y2,double r) {
	if ((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2)>=4*r*r) return true;
	return false;
}

struct Rou{
	int x1,y1,x2,y2;
	void read() {
		scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
	}
};
Rou d[100];
int n;

struct Node {
	int fe,dfn,low,scc,num;
	bool instack;
};
struct Edge {
	int t,ne;
};

Node a[210];
Edge b[40010];
int stk[210];
int m,idx,p;

void putedge(int x,int y) {
	//printf("--%d %d\n",x,y);
	b[p].t=y;
	b[p].ne=a[x].fe;
	a[x].fe=p;
	p++;
}

inline int min(int x,int y) {
	return x<y?x:y;
}

void tarjan(int i) {
	a[i].dfn=a[i].low=idx++;
	a[i].instack=true;
	stk[p++]=i;
	for (int j=a[i].fe;j;j=b[j].ne) {
		if (a[b[j].t].dfn==0) {
			tarjan(b[j].t);
			a[i].low=min(a[i].low,a[b[j].t].low);
		} else if (a[b[j].t].instack) {
			a[i].low=min(a[i].low,a[b[j].t].dfn);
		}
	}
	if (a[i].low==a[i].dfn) {
		p--;
		while (stk[p]!=i) {
			a[stk[p]].instack=false;
			a[stk[p]].scc=i;
			a[i].num++;
			p--;
		}
		a[i].instack=false;
		a[i].scc=i;
		a[i].num++;
	}
}

bool can(double t) {
	int i,j;
	memset(a,0,sizeof(a));
	p=1;
	for (i=0;i<n;i++) {
		for (j=i+1;j<n;j++) {
			if (!canPut(d[i].x1,d[i].y1,d[j].x1,d[j].y1,t)) {
				putedge(i*2,j*2+1);
				putedge(j*2,i*2+1);
			}
			if (!canPut(d[i].x1,d[i].y1,d[j].x2,d[j].y2,t)) {
				putedge(i*2,j*2);
				putedge(j*2+1,i*2+1);
			}
			if (!canPut(d[i].x2,d[i].y2,d[j].x1,d[j].y1,t)) {
				putedge(i*2+1,j*2+1);
				putedge(j*2,i*2);
			}
			if (!canPut(d[i].x2,d[i].y2,d[j].x2,d[j].y2,t)) {
				putedge(i*2+1,j*2);
				putedge(j*2+1,i*2);
			}
		}
	}
	idx=1;
	p=1;
	for (i=n+n-1;i>=0;i--) {
		if (a[i].dfn==0) tarjan(i);
	}
	for (i=0;i<n;i++) {
		//printf("%d %d\n",a[i*2].scc,a[i*2+1].scc);
		if (a[i*2].scc==a[i*2+1].scc) return false;
	}
	return true;
}

int main() {
	int i;
	while (scanf("%d",&n)!=EOF) {
		for (i=0;i<n;i++) d[i].read();
		double l=0,r=10000;
		while (r-l>0.000001) {
			double t=(r+l)/2;
			if (can(t)) l=t;
			else r=t;
		}
		printf("%.2lf\n",l);
	}
	return 0;
}


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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值