hdu3622

Bomb Game

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

Total Submission(s): 3350 Accepted Submission(s): 1149

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构图判断其可行性,对于每
两队位置(u,uu)和(v,vv),如果u和v之间的距离小于2*id,也就
是说位置u和位置v处不能同时防止炸弹(两范围相交),所以连边(u,vv)
和(v,uu),求解强连通分量判断可行性.
为了确保精度问题,在计算过程当中先不开方。。。。。

程序:

#include"stdio.h"
#include"string.h"
#include"stack"
#include"math.h"
#define M 209
using namespace std;
stack<int>q;
int head[M],dfn[M],low[M],belong[M],use[M],t,n,index,num,cnt[M];
struct st
{
int u,v,next;
}edge[M*200];
void init()
{
t=0;
memset(head,-1,sizeof(head));
}
void add(int u,int v)
{
edge[t].u=u;
edge[t].v=v;
edge[t].next=head[u];
head[u]=t++;
}
void tarjan(int u)
{
dfn[u]=low[u]=++index;
q.push(u);
use[u]=1;
int i;
for(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(use[v])
{
low[u]=min(low[u],dfn[v]);
}
}
if(dfn[u]==low[u])
{
int vv;
num++;
do
{
vv=q.top();
belong[vv]=num;
q.pop();
use[vv]=0;
}while(u!=vv);
}
}
void solve()
{
index=num=0;
memset(dfn,0,sizeof(dfn));
memset(use,0,sizeof(use));
for(int i=1;i<=n*2;i++)
{
if(!dfn[i])
tarjan(i);
}
}
double len(double x1,double y1,double x2,double y2)
{
return (x1-x2)*(x1-x2)+(y1-y2)*(y1-y2);
}
int main()
{
int i,j;
double x1[M],y1[M],x2[M],y2[M];
while(scanf("%d",&n)!=-1)
{
for(i=1;i<=n;i++)
scanf("%lf%lf%lf%lf",&x1[i],&y1[i],&x2[i],&y2[i]);
double max1=-1;
for(i=1;i<=n;i++)
{
for(j=i+1;j<=n;j++)
{
double ans=len(x1[i],y1[i],x1[j],y1[j]);
max1=max(max1,ans);
ans=len(x1[i],y1[i],x2[j],y2[j]);
max1=max(max1,ans);
ans=len(x2[i],y2[i],x1[j],y1[j]);
max1=max(max1,ans);
ans=len(x2[i],y2[i],x2[j],y2[j]);
max1=max(max1,ans);
}
}
double left,right,mid;
left=0;
right=max1*2;
while(fabs(right-left)>=0.005)
{ mid=(left+right)/2;
init();
for(i=1;i<=n;i++)
{
for(j=1+i;j<=n;j++)
{
double ans=len(x1[i],y1[i],x1[j],y1[j]);
if(ans<mid)
{
add(i*2-1,j*2);
add(j*2-1,i*2);
}
ans=len(x1[i],y1[i],x2[j],y2[j]);
if(ans<mid)
{
add(2*i-1,2*j-1);
add(2*j,2*i);
}
ans=len(x2[i],y2[i],x1[j],y1[j]);
if(ans<mid)
{
add(2*i,2*j);
add(2*j-1,2*i-1);
}
ans=len(x2[i],y2[i],x2[j],y2[j]);
if(ans<mid)
{
add(2*i,2*j-1);
add(2*j,i*2-1);
}
}
}
solve();
int flag=0;
for(i=1;i<=n;i++)
{
if(belong[i*2-1]==belong[i*2])
{
flag++;
break;
}
}
if(flag)
{
right=mid;
}
else
{
left=mid;
}
}
printf("%.2lf\n",sqrt(mid)/2.0);
}
}

2-sat+二分搜索hdu(3622)的更多相关文章

  1. HDU 3622 Bomb Game(2-sat)

    HDU 3622 Bomb Game 题目链接 题意:求一个最大半径,使得每一个二元组的点任选一个,能够得到全部圆两两不相交 思路:显然的二分半径,然后2-sat去判定就可以 代码: #include ...

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

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

  3. 【HDU 3622】Bomb Game

    http://acm.hdu.edu.cn/showproblem.php?pid=3622 二分答案转化成2-sat问题. 上午测试时总想二分后把它转化成最大点独立集但是不会写最大点独立集暴力又秘制 ...

  4. hdu 3622(二分+2-sat判断可行性)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3622 思路:二分是容易想到的,由于题目中有明显的矛盾关系,因此可以用2-sat来验证其可行性.关键是如 ...

  5. HDU 3622 Bomb Game

    Description \(n\) 个炸弹,每个炸弹有两个放置点,可以任选一个,问你最大的半径是多少. Sol 二分+2-SAT+Tarjan. 首先二分一下答案.然后就成了一个2-SAT问题. 建模 ...

  6. hdu 3622 Bomb Game(二分+2-SAT)

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

  7. HDU 3622 Bomb Game(二分+2SAT)

    题意:有一个游戏,有n个回合,每回合可以在指定的2个区域之一放炸弹,炸弹范围是一个圈,要求每回合的炸弹范围没有重合.得分是炸弹半径最小的值.求可以得到的最大分数. 思路:二分+2SAT. 二分炸弹范围 ...

  8. hdu 3622 二分+2-SAT判定

    思路:如题 #include<iostream> #include<algorithm> #include<cstring> #include<cstdio& ...

  9. Bomb Game HDU - 3622(二分最小值最大化)

    题意: 就是给出n对坐标,每对只能选一个,以选出来的点为圆心,半径自定义,画圆,而这些圆不能覆盖,求半径最小的圆的最大值 解析: 看到最x值最x化,那二分变为判定性问题,然后...然后我就没想到... ...

随机推荐

  1. ubuntu12.04开启虚拟机的unity模式

    终端中输入: sudo add-apt-repository ppa:gnome3-team/gnome3 sudo apt-get update sudo apt-get install gnome ...

  2. 最简单的基于FFMPEG+SDL的音频播放器 ver2 (採用SDL2.0)

    ===================================================== 最简单的基于FFmpeg的音频播放器系列文章列表: <最简单的基于FFMPEG+SDL ...

  3. 云计算中auto-scaling 最早的来源

    什么是弹性?首先,整合计算资源,将计算资源池化,通过虚拟机按需使用计算资源;其次,按量计费,让用户能够根据使用量按月按时甚至按秒来进行付费. 不过,光有了这两条还不够.为什么?我举个例子: 很多做运维 ...

  4. CentOS查看登录用户以及踢出用户

    查看登录用户,使用w命令 [root@lnmp ~]# w 18:51:18 up 35 min,  2 users,  load average: 0.00, 0.00, 0.00 USER     ...

  5. CentOS Linux 下安装Samba

    一.Samba简介: Samba是在Linux和UNIX系统上实现SMB协议的一个免费软件,由服务器及客户端程序构成.Linux中搭建环境有几个需要使用的软件包: (1)samba-client:这个 ...

  6. JavaScript DOM 第3章 DOM

    3.4.5 获取元素 1. getElementById DOM提供了一个名为getElementById的方法,这个方法将返回一个与那个有着给定的id属性值的元素节点对应的对象. 文档中的每个元素都 ...

  7. mac下zephir第一步,安装+hello zephir!

    第一步 安装autoconf re2c automake libtool等依赖,如果没有安装git的记得先安装git brew install autoconf brew install automa ...

  8. php中ignore_user_abort函数的用法(定时)

    PHP中的ignore_user_abort函数是当用户关掉终端后脚本不停止仍然在执行,可以用它来实现计划任务与持续进程,下面会通过实例讨论ignore_user_abort()函数的作用与用法. i ...

  9. 解决 openpyxl 垂直分页符和水平分页符同时添加的问题

    前言 十天前知乎上有人提问 python:openpyxl模块怎么给表格添加分页符?实现分页打印功能?,看到问题之后,我很快的给他了一个如何添加垂直分页符或水平分页符的示例,你以为问题就结束了?我是这 ...

  10. linux中,查看某个进程打开的文件数?

    需求描述: 今天在处理一个问题的时候,涉及到查看某个进程打开的文件数,在此记录下. 操作过程: 1.通过lsof命令查看某个特定的进程打开的文件数 [root@hadoop3 ~]# lsof -p ...