HDU-3622-Bomb Game(2-SAT+二分)

本文介绍了一款名为BombGame的游戏,玩家需要在二维平面上选择放置炸弹的位置,并调整爆炸半径以确保各爆炸范围不相交。文章详细解释了游戏规则及通过二分查找结合2-SAT算法来求解最优策略的方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Bomb Game

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


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
 

给n对炸弹可以放置的坐标位置,每对只能选一个,每个炸弹爆炸的范围半径都一样,

控制爆炸的半径使得所有的爆炸范围都不相交,求解这个最大半径.

直接二分答案,跑一波2-SAT就好。




//#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
const int MAXN = 1e5+7;
const double eps = 1e-5;
int x[MAXN],y[MAXN];
struct node
{
    int v,next;
} edge[MAXN];
int head[MAXN],index;
void add_edge(int u,int v)
{
    edge[index].v=v;
    edge[index].next=head[u];
    head[u]=index++;
}
int DFN[MAXN],low[MAXN],stack_[MAXN],in_stack[MAXN],belong[MAXN];
int cir,top,temp;
void Tarjan(int u)
{
    int p;
    DFN[u]=low[u]=++temp;
    in_stack[u]=1;
    stack_[top++]=u;
    for(int i=head[u]; i+1; i=edge[i].next)
    {
        int v=edge[i].v;
        if(!DFN[v])
        {
            Tarjan(v);
            low[u]=min(low[u],low[v]);
        }
        else if(in_stack[v])
            low[u]=min(low[u],DFN[v]);
    }
    if(low[u]==DFN[u])
    {
        ++cir;
        do
        {
            p=stack_[--top];
            in_stack[p]=0;
            belong[p]=cir;
        }
        while(p!=u);
    }
}
double dist(int i,int j)
{
    return sqrt((double)(x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j]));
}
int main()
{
    int n,m;
    while(scanf("%d",&n)!=EOF)
    {
        for(int i=0; i<n<<1; ++i)
            scanf("%d%d",&x[i],&y[i]);
        double ans;
        double l=0.0,r=40000.0,mid;
        while(r-l>=eps)
        {
            mid=(l+r)/2.0;
            temp=cir=top=index=0;
            memset(DFN,0,sizeof(DFN));
            memset(head,-1,sizeof(head));
            memset(in_stack,0,sizeof(in_stack));
            memset(belong,0,sizeof(belong));
            for(int i=0; i<n<<1; ++i)
                for(int j=i+1; j<n<<1; ++j)
                {
                    if(j-i==1&&i&1==0)continue;
                    if(dist(i,j)<mid*2.0)
                    {
                        add_edge(j^1,i);
                        add_edge(i^1,j);
                    }
                }
            for(int i=0; i<n<<1; ++i)
                if(!DFN[i])Tarjan(i);
            int flag=0;
            for(int i=0; i<n; ++i)
                if(belong[i<<1]==belong[(i<<1)^1])
                {
                    flag=1;
                    break;
                }
            if(!flag){ans=mid;l=mid;}
            else r=mid;
        }
        printf("%.2lf\n",ans);
    }
    return 0;
}





评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值