ACM HDU 3622 Bomb Game(2-SAT)

20798 ワード

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 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
The 35th ACM/ICPC Asia Regional Tianjin Site —— Online Contest
 
Recommend
lcy
 
 
标题:n対の爆弾を置くことができる位置(各位置は2次元平面上の点)を与え、爆弾を置くたびにこの対の中の1つの点しか選択できず、各爆弾の爆発範囲の半径は同じで、爆発の半径を制御してすべての爆発範囲が交差しないように(正接可能)、この最大半径を解く.
     まず最大半径値を二分する、次に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
",Max);
}
return 0;
}