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
Source
2010 Asia Regional Tianjin Site —— Online Contest
Recommend
做了POJ的2_SAT六题,感觉这道题很水~~~~
但是前提是我知道要往2_sat的方向考虑,这种经验的事情就要靠多做题了,OTL
题意很简单。二分+2sat搞定,先二分最小半径,然后枚举点,如果2个点的距离小于2*mid,那么说明有矛盾,按矛盾来建边
#include<queue>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<cmath>
using namespace std;
const int N =205;
struct node
{
int from;
int to;
int next;
}edge[N*N],redge[N*N];
int head[N],rhead[N];
bool instack[N];
int DFN[N],block[N],color[N],in_deg[N],low[N],Stack[N],cfl[N];
int index,tot,sccnum,Top,rtot,n,m;
int dist1[N],dist2[N];//每一只牛到s1,s2的距离
struct node2
{
int x,y;
}Round[N];
void addedge(int from,int to)
{
edge[tot].from=from;
edge[tot].to=to;
edge[tot].next=head[from];
head[from]=tot++;
}
/*void raddedge(int from,int to)
{
redge[rtot].from=from;
redge[rtot].to=to;
redge[rtot].next=rhead[from];
rhead[from]=rtot++;
}*/
void tarjan(int u)
{
DFN[u]=low[u]=++index;
instack[u]=1;
Stack[Top++]=u;
for (int i=head[u];i!=-1;i=edge[i].next)
{
int v=edge[i].to;
if (DFN[v]==-1)
{
tarjan(v);
if(low[u]>low[v])
low[u]=low[v];
}
else if (instack[v] && low[u]>DFN[v])
low[u]=DFN[v];
}
if (DFN[u]==low[u])
{
int v;
sccnum++;
do
{
Top--;
v=Stack[Top];
block[v]=sccnum;
instack[v]=0;
}
while (v!=u);
}
}
/*void topo_sort()
{
queue<int>qu;
memset(color,0,sizeof(color));
for (int i=1;i<=sccnum;i++)
if (in_deg[i]==0)
qu.push(i);
while (!qu.empty())
{
int u=qu.front();
qu.pop();
if (!color[u])
{
color[u]=1;
color[cfl[u]]=-1;
}
for (int i=rhead[u];i!=-1;i=redge[i].next)
{
int v=redge[i].to;
in_deg[v]--;
if (!in_deg[v])
qu.push(v);
}
}
}*/
bool judge()
{
for (int i=0;i<n;i++)
{
if (block[i]==block[i+n])
return false;
//cfl[block[2*i]]=block[2*i+1];
//cfl[block[2*i+1]]=block[2*i];
}
return true;
}
void init()
{
memset(block,-1,sizeof(block));
memset(DFN,-1,sizeof(DFN));
memset(instack,0,sizeof(instack));
index=sccnum=Top=0;
}
/*void r_build()
{
memset(in_deg,0,sizeof(in_deg));
memset(rhead,-1,sizeof(rhead));
rtot=0;
for (int i=0;i<tot;i++)
{
int u=edge[i].from;
int v=edge[i].to;
if (block[u]!=block[v])
{
raddedge(block[v],block[u]);
in_deg[block[u]]++;
}
}
}*/
/*void solve()
{
build();
init();
for (int i=1;i<=2*n;i++)
if (DFN[i]==-1)
tarjan(i);
if (!judge())
printf("bad luck\n");
else
{
bool flag=false;
r_build();
topo_sort();
}*/
inline double dist(int x1,int y1,int x2,int y2)
{
return sqrt(double((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2)));
}
int main()
{
while (~scanf("%d",&n))
{
for(int i=0;i<n;i++)
scanf("%d%d%d%d",&Round[i].x,&Round[i].y,&Round[i+n].x,&Round[i+n].y);
double l=0,r=10000,mid;
while(l+1e-6<r)
{
mid=(l+r)/2;
init();
memset(head,-1,sizeof(head));
tot=0;
for(int i=0;i<n-1;i++)
for(int j=i+1;j<n;j++)
{
if(dist(Round[i].x,Round[i].y,Round[j].x,Round[j].y) < 2*mid)
{
addedge(i,j+n);
addedge(j,i+n);
}
if(dist(Round[i+n].x,Round[i+n].y,Round[j].x,Round[j].y) < 2*mid)
{
addedge(i+n,j+n);
addedge(j,i);
}
if(dist(Round[i].x,Round[i].y,Round[j+n].x,Round[j+n].y) < 2*mid)
{
addedge(i,j);
addedge(j+n,i+n);
}
if(dist(Round[i+n].x,Round[i+n].y,Round[j+n].x,Round[j+n].y) < 2*mid)
{
addedge(i+n,j);
addedge(j+n,i);
}
}
for(int i=0;i<2*n;i++)
if(DFN[i]==-1)
tarjan(i);
if(judge())
l=mid;
else
r=mid;
}
printf("%.2f\n",mid);
}
return 0;
}