HDU3622 Bomb Game

22 篇文章 0 订阅
7 篇文章 0 订阅

Bomb Game

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

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

Source

2010 Asia Regional Tianjin Site —— Online Contest


题目的意思是给出n对炸弹的位置,每对只能引爆1个,引爆的炸弹不能互相炸到,求最大爆炸半径
思路:二分+2-sat 根据枚举的距离矛盾关系建图,然后2-sat判断

#include <iostream>  
#include <cstdio>  
#include <cstring>  
#include <string>  
#include <algorithm>  
#include <cmath>  
#include <map>  
#include <set>  
#include <stack>  
#include <queue>  
#include <vector>  
#include <bitset>  

using namespace std;

#define LL long long  
const int INF = 0x3f3f3f3f;
#define MAXN 100100  
#define MAXM 5000100  

struct node
{
    int u, v, next;
} edge[MAXM];


int dfn[MAXN], low[MAXN], s[MAXN], Stack[MAXN], in[MAXN], block[MAXN],x[MAXN],y[MAXN];
int cnt, tot, index, bnum, ctt;

void init()
{
    memset(s, -1, sizeof s);
    memset(dfn, 0, sizeof dfn);
    memset(low, 0, sizeof low);
    memset(Stack, 0, sizeof Stack);
    memset(in, 0, sizeof in);
    memset(block, 0, sizeof block);
    cnt = tot = index = bnum = 0;
}

void add(int u, int v)
{
    edge[cnt].u = u;
    edge[cnt].v = v;
    edge[cnt].next = s[u];
    s[u] = cnt++;
}

void tarjan(int x)
{
    dfn[x] = low[x] = ++tot;
    Stack[++index] = x;
    in[x] = 1;
    for (int i = s[x]; ~i; i = edge[i].next)
    {
        int v = edge[i].v;
        if (!dfn[v])
        {
            tarjan(v);
            low[x] = min(low[x], low[v]);
        }
        else if (in[v])
        {
            low[x] = min(low[x], low[v]);
        }
    }
    if (dfn[x] == low[x])
    {
        bnum++;
        do
        {
            //printf("%d ",Stack[index]);  
            block[Stack[index]] = bnum;
            in[Stack[index--]] = 0;
        } while (Stack[index + 1] != x);
        // printf("\n");  
    }
}

bool solve()
{
    for (int i = 0; i < ctt; i++)
        if (!dfn[i])
            tarjan(i);

    for (int i = 0; i < ctt; i += 2)
    {
        if (block[i] == block[i ^ 1])
            return 0;
    }
    return 1;
}

double calcdis(int xx1, int yy1, int xx2, int yy2)
{
    return sqrt((xx1 - xx2)*(xx1 - xx2) + (yy1 - yy2)*(yy1 - yy2));
}

int main()
{
    int n;
    while (~scanf("%d", &n))
    {
        ctt = 2 * n;
        for (int i = 0; i < n; i++)
        {
            scanf("%d%d%d%d",& x[2 * i], &y[2 * i], &x[2 * i + 1], &y[2 * i + 1]);
        }

        double l = 0, r = 1000000;
        while (r - l > 1e-7)
        {
            double mid = (l + r) / 2;
            init();
            for (int i = 0; i < n; i++)
            {
                for (int j = i + 1; j < n; j++)
                {
                    int a = 2 * i, b = 2 * j;
                    if (calcdis(x[a], y[a], x[b], y[b]) < 2*mid)
                    {
                        add(a, b ^ 1);
                        add(b, a ^ 1);

                    }
                    if (calcdis(x[a], y[a], x[b^1], y[b^1]) < 2*mid)
                    {
                        add(a, b);
                        add(b^1, a ^ 1);
                    }
                    if (calcdis(x[a^1], y[a^1], x[b], y[b]) < 2*mid)
                    {
                        add(a^1, b ^ 1);
                        add(b, a );
                    }
                    if (calcdis(x[a^1], y[a^1], x[b^1], y[b^1]) < 2*mid)
                    {
                        add(a^1, b);
                        add(b^1, a);
                    }
                }
            }
            if (solve()) l = mid;
            else r = mid;
        }
        printf("%.2f\n",l);

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值