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