HDU 3622 Bomb Game 2-sat

来源:互联网 发布:java初次登陆修改密码 编辑:程序博客网 时间:2024/05/29 16:42

Bomb Game

Time Limit: 10000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 3053    Accepted Submission(s): 1029


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.
 


题目意思:
给你n对点, 然后每一对点可任意选择1个点,然后这些都是中心点,有共同的半径,你要使他们形成的圆互相不覆盖,求最大的半径。

解法:
讲查找性问题转化为判定性问题, 二分不断判断该半径是否可行。直到精度满足要求。

如果i跟j之间距离 < 2*r 。
那么就连接   ~i跟j , 跟  i 与~j

因为此时i跟j不能成立,就取其一对的点来进行连边。


代码:
////  3622.cpp//  ACM_HDU////  Created by ipqhjjybj on 13-9-3.//  Copyright (c) 2013年 ipqhjjybj. All rights reserved.//#include <cstdio>#include <cstdlib>#include <algorithm>#include <cmath>#define pow(x) ((x)*(x))using namespace std;const int N=3333;const int M=111111;int n;bool flag;double di[N][N];const double eps=1e-6;struct node{    int to,next;}Edge[M];struct POINT{    int x,y;}p[N];int cnt,tot,sig,dfn[N],low[N],id[N],head[N],sta[N],sa;void addEdge(int u,int v){    Edge[cnt].to=v;    Edge[cnt].next=head[u];    head[u]=cnt++;}double dist(int i,int j){    return sqrt(pow(p[i].x-p[j].x)*1.0+pow(p[i].y-p[j].y));}void dfs(int u){    int tmp=dfn[u]=low[u]=sig++;    sta[sa++]=u;    for(int q=head[u];q!=-1;q=Edge[q].next){        int v=Edge[q].to;        if(dfn[v]==-1) dfs(v);        tmp=min(tmp,low[v]);    }    if(tmp<low[u]){        low[u]=tmp;        return ;    }    int t;    do{        id[ t=sta[--sa]] = tot;        low[t]=n<<1;    }while(t!=u);    tot++;}void tarjan(){    memset(dfn,-1,sizeof(dfn));    sa=sig=tot=0;    for (int i=0; i<(n<<1);i++ ) {        if(dfn[i]==-1)            dfs(i);    }    for(int i=0;i<n;i++){        if(id[i]==id[n+i]){            flag=false;            return;        }    }}void check(double mid){    int ii,jj;    memset(head,-1,sizeof(head));    cnt=0;    for(int i=0;i<(n<<1);i++){        for(int j=i+1;j<(n<<1);j++){            if(i==j||abs(i-j)==n)continue;            if(mid*2>di[i][j]){                if(i>=n)ii=i-n;                else ii=i+n;                if(j>=n)jj=j-n;                else jj=j+n;                addEdge(j,ii);                addEdge(i,jj);            }                    }    }  //  printf("tarjan mid=%.2lf\n",mid);    tarjan();}void solve(){    double left=0x3f3f3f3f,right=0;    for(int i=0;i<(n<<1);i++){        for(int j=i+1;j<(n<<1);j++){            di[j][i]=di[i][j]=dist(i,j);            right=max(right,di[i][j]);            left=min(left,di[i][j]);        }    }    left/=2.0;    right/=2.0;    double mid;    while(left+eps<right){        mid=(left+right)/2.0;        flag=true;        check(mid);        if(flag){            left=mid+eps;        }else{            right=mid-eps;        }    }    printf("%.2lf\n",left);}int main(){        while(scanf("%d",&n)!=EOF){        for(int i=0;i<n;i++){            scanf("%d %d %d %d",&p[i].x,&p[i].y,&p[i+n].x,&p[i+n].y);        }        solve();    }    return 0;}


原创粉丝点击