hdu3622 2sat加二分

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
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<vector>
#define maxn 10005
using namespace std;
int n,m;
struct round
{
    int a,b,c,d;
}p[maxn];
struct twosat
{
    int n;
    vector<int>g[maxn];
    bool mark[maxn*2];
    int s[maxn*2];
    int c;
    void init(int n)
    {
        this->n=n;
        for(int i=0;i<2*n;i++)
            g[i].clear();
        memset(mark,0,sizeof(mark));
    }
    void addedge(int x,int xval,int y,int yval)
    {
        x=x*2+xval;
        y=y*2+yval;
        g[x].push_back(y);
    }
    bool dfs(int x)
    {
        if(mark[x^1])
            return false;
        if(mark[x])
            return true;
        mark[x]=true;
        s[c++]=x;
        for(int i=0;i<g[x].size();i++)
            if(!dfs(g[x][i]))
            return false;
        return true;
    }
    bool solve()
    {
        for(int i=0;i<2*n;i+=2)
            if(!mark[i]&&!mark[i+1])
        {
            c=0;
        if(!dfs(i))
           {
            while(c>0)
           mark[s[--c]]=false;
           if(!dfs(i+1))
            return false;
        }
        }
        return true;
    }
}TS;
double getdis(int x1,int y1,int x2,int y2)
{
    return sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
}
bool check(double mid)
{TS.init(n);
 for(int i=0;i<n;i++)
    for(int j=i+1;j<n;j++)
 {

     if(getdis(p[i].a,p[i].b,p[j].a,p[j].b)<2*mid)
     {TS.addedge(i,0,j,1);
     TS.addedge(j,0,i,1);
 }
 if(getdis(p[i].c,p[i].d,p[j].c,p[j].d)<2*mid)
 {
     TS.addedge(i,1,j,0);
     TS.addedge(j,1,i,0);
 }
 if(getdis(p[i].a,p[i].b,p[j].c,p[j].d)<2*mid)

 {
     TS.addedge(i,0,j,0);
     TS.addedge(j,1,i,1);
 }
        if(getdis(p[i].c,p[i].d,p[j].a,p[j].b)<2*mid)
        {
            TS.addedge(i,1,j,1);
            TS.addedge(j,0,i,0);
        }
}
return TS.solve();
}
int main()
{while(~scanf("%d",&n))
     {for(int i=0;i<n;i++)
  scanf("%d%d%d%d",&p[i].a,&p[i].b,&p[i].c,&p[i].d);
  double l=0,r=20000.1;
  while(r-l>1e-6)
  {
      double mid=(l+r)/2;
      if(check(mid))
        l=mid;
      else
        r=mid;
  }
  printf("%.2lf\n",l);
    }
    return 0;
}

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章