hdu3622 Bomb Game(二分+2-SAT)

Bomb Game

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


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.
 

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
 

Source

题目大意:一个平面内给n对点,每对点只能放一个炸弹,每个炸弹杀伤以该炸弹为中心的一个圆形区域,每个炸弹杀伤范围相同,杀伤半径任意。现在要求任意2个炸弹杀伤范围不重叠,求炸弹最大杀伤半径。

题目分析:要求杀伤半径,半径范围不超过3000,于是选择二分半径,然后枚举任意两对点之间的相互位置关系,与杀伤半径相比,建图,跑一遍2-SAT找矛盾。

详情请见代码:

#include <iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
using namespace std;
const int N = 205;
const int M = 40005;
const double eps = 1e-5;
double tb[105][105][4];
struct point
{
    int x1,x2,y1,y2;
}pt[105];
struct edge
{
    int to,next;
}g[M];
int head[N];
int scc[N];
bool flag;
int vis[N];
int stack1[N];
int stack2[N];
int n;
int num;

void init()
{
    memset(head,-1,sizeof(head));
    memset(scc,0,sizeof(scc));
    memset(vis,0,sizeof(vis));
    flag = true;
    num = 0;
    stack1[0] = stack2[0] = 0;
}

void build(int s,int t)
{
    g[num].to = t;
    g[num].next = head[s];
    head[s] = num ++;
}

double dis(double x1,double y1,double x2,double y2)
{
    return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
}

void maketable()
{
    int i,j;
    for(i = 1;i < n;i ++)
    {
        for(j = i + 1;j <= n;j ++)
        {
            tb[i][j][0] = dis(pt[i].x1,pt[i].y1,pt[j].x1,pt[j].y1);
            tb[i][j][1] = dis(pt[i].x1,pt[i].y1,pt[j].x2,pt[j].y2);
            tb[i][j][2] = dis(pt[i].x2,pt[i].y2,pt[j].x1,pt[j].y1);
            tb[i][j][3] = dis(pt[i].x2,pt[i].y2,pt[j].x2,pt[j].y2);
        }
    }
}

void dfs(int cur,int &sig,int &cnt)
{
    if(!flag)
        return;
    vis[cur] = ++sig;
    stack1[++stack1[0]] = cur;
    stack2[++stack2[0]] = cur;
    for(int i = head[cur];i != -1;i = g[i].next)
    {
        if(!vis[g[i].to])
            dfs(g[i].to,sig,cnt);
        else
        {
            if(scc[g[i].to] == 0)
            {
                while(vis[stack2[stack2[0]]] > vis[g[i].to])
                    stack2[0] --;
            }
        }
    }
    if(stack2[stack2[0]] == cur)
    {
        ++cnt;
        stack2[0] --;
        do
        {
            scc[stack1[stack1[0]]] = cnt;
            int tmp = stack1[stack1[0]];
            if(tmp > n)
            {
                if(scc[tmp - n] && scc[tmp - n] == cnt)
                {
                    flag = false;
                    return;
                }
            }
            else
            {
                if(scc[tmp + n] && scc[tmp + n] == cnt)
                {
                    flag = false;
                    return;
                }
            }
        }while(stack1[stack1[0] --] != cur);
    }
}

bool Gabow()
{
    int i,sig,cnt;
    sig = cnt = 0;
    for(i = 1;i <= n + n && flag;i ++)
        if(!vis[i])
            dfs(i,sig,cnt);
    return flag;
}

int main()
{
    int i,j;
    while(scanf("%d",&n) != EOF)
    {
        for(i = 1;i <= n;i ++)
        {
            scanf("%d%d%d%d",&pt[i].x1,&pt[i].y1,&pt[i].x2,&pt[i].y2);
         }
        maketable();
        double l,r,mid;
        l = 0.0;
        r = 30000.0;
        double ans;
        while(r - l > eps)
        {
            mid = (l + r) / 2;
            init();
            for(i = 1;i < n;i ++)
            {
                for(j = i + 1;j <= n;j ++)
                {
                    if(tb[i][j][0] - mid < eps)//i j
                    {
                        build(i,j + n);
                        build(j,i + n);
                    }
                    if(tb[i][j][1] - mid < eps)//i j + n
                    {
                        build(i,j);
                        build(j + n,i + n);
                    }
                    if(tb[i][j][2] - mid < eps)//i + n j
                    {
                        build(i + n,j + n);
                        build(j,i);
                    }
                    if(tb[i][j][3] - mid < eps)
                    {
                        build(i + n,j);
                        build(j + n,i);
                    }
                }
            }
            if(Gabow())
            {
                ans = mid;
                l = mid;
            }
            else
                r = mid;
        }
        printf("%.2lf\n",ans/2);
    }
    return 0;
}
//140MS	868K




  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值