hdu3622 2-SAT+二分

http://acm.hdu.edu.cn/showproblem.php?pid=3622

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

/**
hdu3622 2-SAT
题目大意:给定一组的点,一组有两个,每组必须的只能选择一个,不可不选,然后以选择的点画圆,问在所有圆的不能相交(可以相切)的情况下最大的可行半径是多少
解题思路:二分查找可行半径,每次利用2-sat建边,若满足则当前半径值可以,那么找出最大的即可。
*/
#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <string.h>
#include <math.h>
#include <stack>
using namespace std;
const int maxn=210;
const double eps=1e-5;

int head[maxn],ip;
int dfn[maxn],low[maxn],sccno[maxn],cnt,scc,instack[maxn];
int n;
stack<int>stc;

void init()
{
    memset(head,-1,sizeof(head));
    ip=0;
}

struct note
{
    int v,next;
} edge[maxn*maxn*2];

void addedge(int u,int v)
{
    edge[ip].v=v,edge[ip].next=head[u],head[u]=ip++;
}

void add_cluse(int x,int xval,int y,int yval)
{
    x=x*2+xval;
    y=y*2+yval;
    addedge(x,y^1);
    addedge(y,x^1);
}

void dfs(int u)
{
    dfn[u]=low[u]=++scc;
    stc.push(u);
    instack[u]=1;
    for(int i=head[u]; i!=-1; i=edge[i].next)
    {
        int v=edge[i].v;
        if(!dfn[v])
        {
            dfs(v);
            low[u]=min(low[u],low[v]);
        }
        else if(instack[v])
        {
            low[u]=min(low[u],dfn[v]);
        }
    }
    if(low[u]==dfn[u])
    {
        cnt++;
        int x;
        do
        {
            x=stc.top();
            stc.pop();
            sccno[x]=cnt;
            instack[x]=0;
        }
        while(x!=u);
    }
}

bool solve()
{
    scc=cnt=0;
    memset(sccno,0,sizeof(sccno));
    memset(dfn,0,sizeof(dfn));
    memset(low,0,sizeof(low));
    memset(instack,0,sizeof(instack));
    while(!stc.empty())stc.pop();
    for(int i=0; i<2*n; i++)
    {
        if(!dfn[i])
            dfs(i);
    }
    for(int i=0; i<2*n; i+=2)
    {
        if(sccno[i]==sccno[i^1])return false;
    }
    return true;
}

struct node
{
    double x,y;
} a[maxn][2];

double dis(node a,node b)
{
    return (a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y);
}

int main()
{
    while(~scanf("%d",&n))
    {
        for(int i=0; i<n; i++)
        {
            scanf("%lf%lf%lf%lf",&a[i][0].x,&a[i][0].y,&a[i][1].x,&a[i][1].y);
        }
        double l=0,r=40000.0;
        while(r-l>=eps)
        {
            double mid=(l+r)/2;
           // printf("%lf\n",mid);
            init();
            for(int i=0; i<n; i++)
            {
                for(int u=0; u<2; u++)
                {
                    for(int j=i+1; j<n; j++)
                    {
                        for(int v=0;v<2;v++)
                        {
                            if(dis(a[i][u],a[j][v])<mid*mid*4.0)//不满足
                            {
                              //  printf("%lf %lf\n",dis(a[i][u],a[j][v]),mid*mid);
                                add_cluse(i,u,j,v);
                              //  printf("%d,%d;%d,%d\n",i,u,j,v);
                            }
                        }
                    }
                }
            }
           // getchar();
            if(solve())l=mid;
            else r=mid;
        }
        printf("%.2lf\n",r);
    }
    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值