HDU 3622 Bomb Game 【二分+2-SAT】

本文深入探讨了在一款名为'BombGame'的计算机游戏中,如何通过优化策略和使用算法来最大化游戏得分。游戏要求玩家在二维平面上选择放置炸弹的位置,并控制爆炸半径,避免任何两个爆炸圈的重叠区域,最终目标是最小化所有炸弹的半径。文章提供了详细的算法实现,包括使用二分查找确定最小半径和构建图模型进行冲突分析。

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


传送门:HDU 3622


Bomb Game
Time Limit: 10000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)

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


AC代码:

#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<vector>
#include<cmath>
#define ll long long
#define inf 0x3f3f3f3f
using namespace std;
const int N=1100;
int n,top;
bool mark[2*N];
int stack[2*N];
vector<int> g[2*N];
struct Node
{
  int x,y;
}c[2*N];
double getd(Node a,Node b)//计算圆心距
{
  int x=a.x-b.x,y=a.y-b.y;
  return sqrt(x*x*1.0+y*y*1.0);
}
void init()
{
  memset(mark,false,sizeof(mark));
  for(int i=0;i<2*N;i++)
    g[i].clear();
}
void AddEdge(int x,int y)
{
  g[x].push_back(y);
}
bool dfs(int x)
{
  if(mark[x^1]) return false;
  if(mark[x]) return true;
  mark[x]=true;
  stack[++top]=x;
  int len=g[x].size();
  for(int i=0;i<len;i++)
  {
    if(!dfs(g[x][i])) return false;
  }
  return true;
}
bool twosat()
{
  for(int i=0;i<2*n;i+=2)
  {
    if(!mark[i]&&!mark[i+1])
    {
      top=0;
      if(!dfs(i))
      {
        while(top>0)
          mark[stack[top--]]=false;
        if(!dfs(i+1)) return false;
      }
    }
  }
  return true;
}
int main()
{
  int x1,y1,x2,y2;
  while(scanf("%d",&n)!=EOF)
  {
    init();
    for(int i=0;i<n;i++)
    {
      scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
      c[2*i].x=x1;c[2*i].y=y1;
      c[2*i+1].x=x2;c[2*i+1].y=y2;
    }
    double l=0,r=100000;
    while(r-l>0.00001)//二分最小半径
    {
      init();
      double mid=(l+r)/2.0;
      for(int i=0;i<n;i++)
      {
        for(int j=i+1;j<n;j++)
        {
          if(getd(c[2*i],c[2*j])<2*mid)//判断是否相交,相交及有矛盾关系
          {
            AddEdge(2*i,2*j+1);
            AddEdge(2*j,2*i+1);
          }
          if(getd(c[2*i],c[2*j+1])<2*mid)
          {
            AddEdge(2*i,2*j);
            AddEdge(2*j+1,2*i+1);
          }
          if(getd(c[2*i+1],c[2*j])<2*mid)
          {
            AddEdge(2*i+1,2*j+1);
            AddEdge(2*j,2*i);
          }
          if(getd(c[2*i+1],c[2*j+1])<2*mid)
          {
            AddEdge(2*i+1,2*j);
            AddEdge(2*j+1,2*i);
          }
        }
      }
      if(twosat())
      {
        l=mid;
      }
      else r=mid;
    }
    printf("%.2f\n",l);
  }
  return 0;
}


相似题目:POJ 2749

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值