题意:
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, y1i, 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
思路:
这个题比较明显的二分+2-sat,不过,比较有意思的是中间建边的形式,一来是我想的是按组进行匹配分析,发现会建重边,不然就很复杂,
以拆分后的点进行挨个判断,又不能与同一组的点进行匹配,简单,所以也算是涨姿势,,,
代码:
#include<bits/stdc++.h>
using namespace std;
const int maxn=2005;
const int maxm=maxn*maxn;
struct node{int u,next;}edge[maxm*10];
int head[maxn],cnt, vis[maxn],dfn[maxn],low[maxn],belong[maxn],id,cnt2;
stack<int>s;
struct AA
{
int x,y;
}pos[maxn];
void init()
{
memset(head,-1,sizeof(head));cnt=0;id=0;
while(!s.empty())s.pop();
cnt2=0;
memset(vis,0,sizeof(vis));
memset(dfn,-1,sizeof(dfn));
memset(low,-1,sizeof(low));
memset(belong,-1,sizeof(belong));
}
void addedge(int a,int b)
{
edge[cnt].u=b;
edge[cnt].next=head[a];
head[a]=cnt++;
}
void tarjan(int now)
{
dfn[now]=low[now]=id++;
vis[now]=1;s.push(now);
for(int i=head[now];i!=-1;i=edge[i].next)
{
int next=edge[i].u;
if(dfn[next]==-1)
{
tarjan(next);
low[now]=min(low[now],low[next]);
}
else if(vis[next]==1)
{
low[now]=min(low[now],dfn[next]);
}
}
if(low[now]==dfn[now]){cnt2++;
while(1)
{
int tmp;
tmp=s.top(),s.pop();
vis[tmp]=0;
belong[tmp]=cnt2;
if(tmp==now) break;
}
}
}
double dis(int i,int j)
{
return sqrt(1.0*(pos[i].x-pos[j].x)*(pos[i].x-pos[j].x)+1.0*(pos[i].y-pos[j].y)*(pos[i].y-pos[j].y));
}
int tr[10005];
int main()
{
int n,m;
while(scanf("%d",&n)==1)
{
for(int i=0;i<n;i++)
{
scanf("%d%d%d%d",&pos[i<<1].x,&pos[i<<1].y,&pos[i<<1|1].x,&pos[i<<1|1].y);
}
double l=0,r=50000,mid=0;
while(1)
{
if(abs((l+r)/2-mid)<=0.00001) break;
mid=(l+r)/2;
init();//cout<<l<<" "<<r<<" "<<mid<<endl;
for(int i=0;i<2*n-2;i++)
{
for(int j=i+(i%2==1?1:2);j<2*n;j++)
if(dis(i,j)<2*mid)//冲突了
{ addedge(i,j^1);//一对里面必须选一个而且只能选一个
addedge(j,i^1);//^1表示选i这对里面的另一个
}
}
for(int i=0;i<2*n;i++)
if(dfn[i]==-1) tarjan(i);
bool flag=true;
for(int i=0;i<n;i++)
{
if(belong[2*i]==belong[2*i+1])
{flag=false;break;}
}
if(flag) l=mid;
else r=mid;
}
printf("%.2lf\n",l);
}
return 0;
}