您的位置:首页 > 其它

hdu 3622 Bomb Game(2-SAT 二分)

2015-05-02 21:21 369 查看


Bomb Game

Time Limit: 10000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)

Total Submission(s): 4156 Accepted Submission(s): 1464



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




给出n组点 每组有两个点 但是每组只能选一个点 以这些点作为圆心画圆

求出这些圆中最小半径的最大值

每组点中选取一个 看这个点能不能与其他点共存 2-SAT的思想

二分距离 如果点i j之间的距离小于二分的值 则说明这两个点不能共存 及pi与pj为假 从而可以建图

#include <cstdio>
#include <iostream>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <string.h>
#include <string>
#include <vector>
#include <queue>

#define MEM(a,x) memset(a,x,sizeof a)
#define eps 1e-8
#define MOD 10009
#define MAXN 10010
#define MAXM 100010
#define INF 99999999
#define ll __int64
#define bug cout<<"here"<<endl
#define fread freopen("ceshi.txt","r",stdin)
#define fwrite freopen("out.txt","w",stdout)

using namespace std;

int Read()
{
    char ch;
    int a = 0;
    while((ch = getchar()) == ' ' | ch == '\n');
    a += ch - '0';
    while((ch = getchar()) != ' ' && ch != '\n')
    {
        a *= 10;
        a += ch - '0';
    }
    return a;
}

void Print(int a)
{
     if(a>9)
         Print(a/10);
     putchar(a%10+'0');
}

struct Edge
{
    int to,next;
}edge[MAXM];
int head[MAXN],tot;
int low[MAXN],dfn[MAXN],stack[MAXN],belong[MAXN];
int index,top,scc;
bool instack[MAXN];

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

void Tarjan(int u)
{
    int v;
    low[u]=dfn[u]=++index;
    stack[top++]=u;
    instack[u]=1;
    for(int i=head[u];i!=-1;i=edge[i].next)
    {
        v=edge[i].to;
        if(!dfn[v])
        {
            Tarjan(v);
            if(low[u]>low[v])
                low[u]=low[v];
        }
        else if(instack[v]&&low[u]>dfn[v])
            low[u]=dfn[v];
    }
    if(low[u]==dfn[u])
    {
        scc++;
        do
        {
            v=stack[--top];
            instack[v]=0;
            belong[v]=scc;
        }while(v!=u);
    }
}
int solve(int n)
{
    MEM(dfn,0); MEM(instack,0);
    index=scc=top=0;
    for(int i=0;i<n;i++)
        if(!dfn[i])
            Tarjan(i);
    for(int i=0;i<n;i+=2)
    {
        if(belong[i]==belong[i^1])
            return 0;
    }
    return 1;
}

void init()
{
    tot=0;
    MEM(head,-1);
}

struct Point
{
    double x,y;
}po[MAXN];
double len(Point p1,Point p2)
{
    return sqrt((p1.x-p2.x)*(p1.x-p2.x)+(p1.y-p2.y)*(p1.y-p2.y));
}

int main()
{
//    fread;
    int n;
    while(scanf("%d",&n)!=EOF)
    {
        for(int i=0;i<n;i++)
            scanf("%lf%lf%lf%lf",&po[i*2].x,&po[i*2].y,&po[i*2+1].x,&po[i*2+1].y);
        double left=0.0,right=40000.0,mid;
        while(right-left>=eps)
        {
            mid=(right+left)/2.0;
            init();
            for(int i=0;i<2*n;i++)
            {
                int k;
                if(i%2==0)
                    k=i+2;
                else k=i+1;
                for(int j=k;j<2*n;j++)
                {
                    double l=len(po[i],po[j]);
                    if(l<2*mid)
                    {
                        addedge(i,j^1);
                        addedge(j,i^1);
                    }
                }
            }
            int flag=solve(2*n);
            if(flag) left=mid;
            else right=mid;
        }
        printf("%.2lf\n",right);
    }
    return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: