Bomb Game

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


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 x1i, y1i, x2i, y2i, indicating that the coordinates of the two candidate places of the i-th round are (x1i, y1i) and (x2i, y2i). 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
 
 
题意:给n对炸弹可以放置的位置(每个位置为一个二维平面上的点),每次放置炸弹是时只能选择这一对中的其中一个点,每个炸弹爆炸的范围半径都一样,控制爆炸的半径使得所有的爆炸范围都不相交(可以相切),求解这个最大半径.
     首先二分最大半径值,然后2-sat构图判断其可行性,对于每两队位置(u,uu)和(v,vv),如果u和v之间的距离小于2*id,也就是说位置u和位置v处不能同时防止炸弹(两范围相交),所以连边(u,vv)和(v,uu),求解强连通分量判断可行性.
#include<stdio.h>
#include
<math.h>
#include
<iostream>
using namespace std;
const int MAXN=205;
const int MAXM=40005;
#define eps 1e-4
struct Node
{
int x,y;
}s[MAXN];
struct Node1
{
int from,to,next;
}edge1[MAXM],edge2[MAXM];
int visit1[MAXN],visit2[MAXN],head1[MAXN],head2[MAXN],Belong[MAXN],T[MAXN];
int tol1,tol2,Bcnt,Tcnt;
void add(int a,int b)
{
edge1[tol1].from
=a;edge1[tol1].to=b;edge1[tol1].next=head1[a];head1[a]=tol1++;
edge2[tol2].from
=b;edge2[tol2].to=a;edge2[tol2].next=head2[b];head2[b]=tol2++;
}
void dfs1(int x)
{
int j;
visit1[x]
=1;
for(j=head1[x];j!=-1;j=edge1[j].next)
if(visit1[edge1[j].to]==0) dfs1(edge1[j].to);
T[Tcnt
++]=x;
}
void dfs2(int x)
{
int j;
visit2[x]
=1;
Belong[x]
=Bcnt;
for(j=head2[x];j!=-1;j=edge2[j].next)
if(visit2[edge2[j].to]==0) dfs2(edge2[j].to);
}
double dist(int x1,int y1,int x2,int y2)
{
return sqrt((double)(x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
}
int main()
{
int i,j,n,ans;
double left,right,mid,Max,ans1;
while(scanf("%d",&n)!=EOF)
{
for(i=0;i<n;i++)
{
scanf(
"%d%d%d%d",&s[2*i].x,&s[2*i].y,&s[2*i+1].x,&s[2*i+1].y);
}
right
=20000*sqrt(2.0);
left
=0;
Max
=0;
while(right-left>=eps)
{
mid
=(right+left)/2;
for(i=0;i<2*n;i++)
{
head1[i]
=-1;
head2[i]
=-1;
visit1[i]
=0;
visit2[i]
=0;
}
tol1
=tol2=Bcnt=Tcnt=0;
for(i=0;i<2*n-2;i++)
{
if(i%2==1) ans=i+1;
else ans=i+2;
for(j=ans;j<2*n;j++)
{
ans1
=dist(s[i].x,s[i].y,s[j].x,s[j].y);
if(ans1<2*mid)
{
add(i,j
^1);
add(j,i
^1);
}
}
}
for(i=0;i<2*n;i++)
if(visit1[i]==0) dfs1(i);
for(i=Tcnt-1;i>=0;i--)
{
if(visit2[T[i]]==0)
{
dfs2(T[i]);
Bcnt
++;
}
}
for(i=0;i<=2*n-2;i+=2)
{
if(Belong[i]==Belong[i+1])break;
}
if(i<=2*n-2) right=mid-eps;//可以不减
else
{
Max
=mid;
left
=mid+eps;//可以不加eps
}
}
printf(
"%.2lf\n",Max);
}
return 0;
}


文章来源:http://www.cnblogs.com/kuangbin/archive/2011/08/22/2149936.html