码迷,mamicode.com
首页 > 其他好文 > 详细

hdu3622 2-SAT+二分

时间:2015-08-26 12:00:22      阅读:123      评论:0      收藏:0      [点我收藏+]

标签:

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 x1i, y1i, x2i, y2i, indicating that the coordinates of the two candidate places of the i-th round are (x1i, y1i) and (x2i, y2i). 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;
}


版权声明:本文为博主原创文章,未经博主允许不得转载。

hdu3622 2-SAT+二分

标签:

原文地址:http://blog.csdn.net/lvshubao1314/article/details/48001397

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!