hdu 3622 Bomb Game (二分+2-sat)

Bomb Game

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


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个炸弹杀伤范围不重叠,求炸弹最大杀伤半径。

思路:
二分半径,建图,2-sat判定。

代码:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <string>
#include <map>
#include <stack>
#include <vector>
#include <set>
#include <queue>
#pragma comment (linker,"/STACK:102400000,102400000")
#define maxn 205
#define MAXN 40005
#define mod 1000000007
#define INF 0x3f3f3f3f
#define pi acos(-1.0)
#define eps 1e-6
typedef long long ll;
using namespace std;

int n,m,num,flag;
double ans;
double dist[maxn][maxn];
int x[maxn],y[maxn];
int head[maxn];
int scc[maxn];
int vis[maxn];
int stack1[maxn];
int stack2[maxn];
struct edge
{
    int v,next;
} g[MAXN];

void init()
{
    memset(head,0,sizeof(head));
    memset(vis,0,sizeof(vis));
    memset(scc,0,sizeof(scc));
    stack1[0] = stack2[0] = num = 0;
    flag = 1;
}
void addedge(int u,int v)
{
    num++;
    g[num].v = v;
    g[num].next = head[u];
    head[u] = num;
}
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; i = g[i].next)
    {
        if(!vis[g[i].v]) dfs(g[i].v,sig,cnt);
        else
        {
            if(!scc[g[i].v])
            {
                while(vis[stack2[stack2[0]]] > vis[g[i].v])
                    stack2[0] --;
            }
        }
    }
    if(stack2[stack2[0]] == cur)
    {
        stack2[0] --;
        ++cnt;
        do
        {
            scc[stack1[stack1[0]]] = cnt;
            int tmp = stack1[stack1[0]];
            if((tmp >n && scc[tmp - n] == cnt) || (tmp <= n && scc[tmp + n] == cnt))  // 注意这里的‘=’号
            {
                flag = false;
                return;
            }
        }
        while(stack1[stack1[0] --] != cur);
    }
}
void Twosat()
{
    int i,sig,cnt;
    sig = cnt = 0;
    for(i=0; i<n+n&&flag; i++)
    {
        if(!vis[i]) dfs(i,sig,cnt);
    }
}
double caldist(int k1,int k2)
{
    double xx,yy;
    xx=x[k1]-x[k2];
    yy=y[k1]-y[k2];
    return sqrt(xx*xx+yy*yy);
}
void presolve()
{
    int i,j;
    for(i=1;i<=2*n;i++)
    {
        for(j=i+1;j<=2*n;j++)
        {
            dist[i][j]=dist[j][i]=caldist(i,j);
        }
    }
}
void build(double dd)
{
    int i,j,t1,t2;
    for(i=1;i<=2*n;i++)
    {
        for(j=i+1;j<=2*n;j++)
        {
            if(dist[i][j]<2*dd)
            {
                t1=j>n?j-n:j+n;
                t2=i>n?i-n:i+n;
                addedge(i,t1);
                addedge(j,t2);
            }
        }
    }
}
void solve()
{
    int i,j;
    double le=0,ri=INF,mid;
    while(ri-le>eps)
    {
        mid=(le+ri)/2;
        init();
        build(mid);
        Twosat();
        if(flag) le=mid;
        else ri=mid;
    }
    ans=le;
}
int main()
{
    int i,j,t;
    while(~scanf("%d",&n))
    {
        for(i=1;i<=n;i++)
        {
            scanf("%d%d%d%d",&x[i],&y[i],&x[i+n],&y[i+n]);
        }
        presolve();
        solve();
        printf("%.2f\n",ans);
    }
    return 0;
}



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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值