HDU 3622 Bomb Game 2-sat +2分

C - Bomb Game
Time Limit:3000MS    Memory Limit:32768KB    64bit IO Format:%I64d & %I64u
Submit Status Practice HDU 3622
Appoint description:

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


每次选择从2个炸弹中选择放置一个炸弹

每个炸弹的爆炸半径可控问如何放置让爆炸半径最大

两个炸弹爆炸范围不相交

二分半径范围即可

ACcode:

#include <map>
#include <queue>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <stdlib.h>
#include <iostream>
#include <algorithm>
#define maxn 100000
#define esp 1e-5
using namespace std;
struct Node{int to,next;}edge[maxn];
int head[maxn],tot;
void add(int u,int v){edge[tot].to=v;edge[tot].next=head[u];head[u]=tot++;}
int low[maxn],dfn[maxn],Stack[maxn],Belong[maxn];
bool Instack[maxn];
int Index,scc,top;
void init(){tot=0;memset(head,-1,sizeof(head));}
void tarjan(int u){
    int v;
    low[u]=dfn[u]=++Index;
    Stack[top++]=u;
    Instack[u]=true;
    for(int i=head[u];i!=-1;i=edge[i].next){
        v=edge[i].to;
        if(!dfn[v]){tarjan(v);low[u]=min(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]=false;
            Belong[v]=scc;
        }while(v!=u);
    }
}
bool solve(int n){
    memset(dfn,0,sizeof(dfn));
    memset(Instack,false,sizeof(Instack));
    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 false;
    return true;
}
struct P{int x,y;void in(){scanf("%d%d",&x,&y);}};
double dist(P a,P b){return sqrt((double)(a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));}
P my[maxn],a[maxn],b[maxn];
int main(){
    int n,x1,x2,y1,y2,N;
    while(~scanf("%d",&n)){
        N=n<<1;
        for(int i=0;i<n;++i){
            my[i*2].in();
            my[i*2+1].in();
        }
        double lf=0,rt=40000,mid;
        while(lf<=rt-esp){
            mid=(lf+rt)/2;
            init();
            for(int i=0;i<N-1;++i){
                for(int j=2+i-i%2;j<N;++j){
                    if(dist(my[i],my[j])<2*mid){
                        add(i,j^1);
                        add(j,i^1);
                    }
                }
            }
            if(solve(N))lf=mid;
            else rt=mid;
        }
        printf("%.2lf\n",lf);
    }
    return 0;
}


你可能感兴趣的:(C++,HDU)