hdu 3622 Bomb Game (2-SAT)

41 篇文章 0 订阅

Bomb Game

Time Limit: 10000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 5369    Accepted Submission(s): 1912


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
 

Recommend
lcy   |   We have carefully selected several similar problems for you:   3625  3628  3629  3627  3621 
 

Statistic |  Submit |  Discuss | Note

题解:2-SAT

二分答案,二分最终方案中最近两点的距离(因为这个距离的1/2就是圆的半径)

关键是如何进行check

如果两个点a,b之间的距离小于mid,那么这两个点一定不能同时入选。

也就是选择了a必然要选择b',选择了b必然要选择a'。所以a->b',b->a'

然后用tarjan进行缩点,如果a,a'在同一个强连通分量中则说明mid不可行。

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#define N 1003
#define eps 1e-4
using namespace std;
int n,m,top,tot,sz,cnt,belong[N];
int point[N],v[N*N],nxt[N*N],num[N][3],dfsn[N],low[N],st[N],ins[N];
double a[N][3],b[N][3];
void add(int x,int y)
{
	tot++; nxt[tot]=point[x]; point[x]=tot; v[tot]=y;
	//cout<<x<<" "<<y<<endl;
}
void tarjan(int x)
{
	dfsn[x]=low[x]=++sz; st[++top]=x;
	ins[x]=1;
	for (int i=point[x];i;i=nxt[i]) {
		int j=v[i];
		if (!dfsn[j]) tarjan(j),low[x]=min(low[x],low[j]);
		else if (ins[j]) low[x]=min(low[x],dfsn[j]);
	}
	if (low[x]==dfsn[x]) {
		int j; ++cnt;
		do{
			j=st[top--];
			belong[j]=cnt;
			ins[j]=0;
		}while (j!=x);
	}
}
double pow(double x){
	return x*x;
}
double getdis(double x,double y,double px,double py){
	return sqrt(pow(x-px)+pow(y-py));
}
bool check(double mid)
{
	//cout<<mid<<endl;
	tot=0; sz=0; cnt=0; top=0;
	memset(point,0,sizeof(point));
	for (int i=1;i<n;i++)
	 for (int l=0;l<=1;l++) {
	 	double x=a[i][l],y=b[i][l];
	 	for (int j=i+1;j<=n;j++)
	 	 for (int k=0;k<=1;k++){
	 	 	double px=a[j][k],py=b[j][k];
	 	 	if (getdis(x,y,px,py)<mid) 
	 	 	 add(num[i][l],num[j][k^1]),add(num[j][k],num[i][l^1]);
		  }
	 }
	memset(dfsn,0,sizeof(dfsn));
	memset(ins,0,sizeof(ins));
	memset(belong,0,sizeof(belong));
	for (int i=1;i<=n+n;i++)
	 if (!dfsn[i]) tarjan(i);
	for (int i=1;i<=n;i++)
	 if (belong[i]==belong[i+n]) return false;
	return true;
}
int main()
{
//	freopen("bomb.in","r",stdin);
//	freopen("bomb.out","w",stdout);
	while (scanf("%d",&n)!=EOF){
		for (int i=1;i<=n;i++)
		 scanf("%lf%lf%lf%lf",&a[i][0],&b[i][0],&a[i][1],&b[i][1]);
		for (int i=1;i<=n;i++) num[i][0]=i,num[i][1]=i+n;
	    double l=0; double r=10000000; double ans=0;
	    while (r-l>=eps) {
	    	double mid=(l+r)/2;
	    	if (check(mid)) ans=max(ans,mid),l=mid+eps;
	    	else r=mid-eps;
		}
		printf("%.2lf\n",ans/2.0);
    }
}



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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值