HDU 3622 Bomb Game 2-sat

73 篇文章 21 订阅
56 篇文章 0 订阅

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 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.
 


题目意思:
给你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;
}


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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值