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

67 篇文章 1 订阅
8 篇文章 0 订阅

Bomb Game

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


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
 

Recommend
lcy
 
题意:给你n对点,每对中选出一个点,画一个圆,所有圆不能相交,使得最小的圆的半径最大
分析:这题要不是知道是2-sat确实无从下手,知道后就简单了,二分答案,那么就知道哪些点不能同时选了,也就是典型的2-sat判定问题,写个二分+强连通搞定
把计算点的距离放到外面初始化,快n倍啊,从2000++ms降到300++ms
PS:2-sat居然跟几何扯上关系了= =,一开始强连通变量搞错wa了,后来低估了答案的大小,又wa了好几次T_T
代码:
#include<cmath>
#include<cstdio>
#include<iostream>
using namespace std;
typedef double diy;
const int mm=99999;
const int mn=222;
struct point
{
    diy x,y;
}g[mm];
int ver[mm],next[mm];
int head[mn],dfn[mn],low[mn],q[mn],id[mn];
int i,j,k,n,idx,top,cnt,edge;
void add(int u,int v)
{
    ver[edge]=v,next[edge]=head[u],head[u]=edge++;
}
void dfs(int u)
{
    dfn[u]=low[u]=++idx;
    q[top++]=u;
    for(int i=head[u],v;i>=0;i=next[i])
        if(!dfn[v=ver[i]])
            dfs(v),low[u]=min(low[u],low[v]);
        else if(!id[v])low[u]=min(low[u],dfn[v]);
    if(dfn[u]==low[u])
    {
        id[u]=++cnt;
        while(q[--top]!=u)id[q[top]]=cnt;
    }
}
void Tarjan()
{
    for(idx=top=cnt=i=0;i<n+n;++i)dfn[i]=id[i]=0;
    for(i=0;i<n+n;++i)
        if(!dfn[i])dfs(i);
}
diy d[mn][mn],l,r,m;
diy Dis(point p,point q)
{
    return sqrt((p.x-q.x)*(p.x-q.x)+(p.y-q.y)*(p.y-q.y));
}
bool ok()
{
    for(edge=i=0;i<n+n;++i)head[i]=-1;
    for(i=0;i<n+n;++i)
        for(j=i+1;j<n+n;++j)
            if((i%n)!=(j%n)&&d[i][j]<2*m)
                add(i,(j+n)%(2*n)),add(j,(i+n)%(2*n));
    Tarjan();
    for(i=0;i<n;++i)
        if(id[i]==id[i+n])return 0;
    return 1;
}
int main()
{
    while(~scanf("%d",&n))
    {
        for(i=0;i<n;++i)
            scanf("%lf%lf%lf%lf",&g[i].x,&g[i].y,&g[i+n].x,&g[i+n].y);
        for(i=0;i<n+n;++i)
            for(j=0;j<n+n;++j)
                d[i][j]=Dis(g[i],g[j]);
        l=0,r=1e5;
        while(r-l>1e-4)
        {
            m=(l+r)/2;
            if(ok())l=m;
            else r=m;
        }
        printf("%.2lf\n",m);
    }
    return 0;
}


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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值