[2-sat]HDOJ3622 Bomb Game
题意:给n对炸弹,每对炸弹选其中一个爆炸。
每个炸弹爆炸的半径相同 圆不能相交, 求最大半径
二分半径, 枚举n*2个炸弹
若i炸弹与j炸弹的距离小于半径*2 则建边
比如 第一对炸弹的第一个 与 第二对炸弹的第一个 距离小于半径*2
则 建立 第一对炸弹的第一个$\Rightarrow $第二对炸弹的第二个 、第二对炸弹的第一个$\Rightarrow $第一对炸弹的第二个
然后 通过判断能否取到n个炸弹 来判断 能否取该半径
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<double, double> PI;
const double eps=1e-;
#define INF 0x3f3f3f3f const int N=*;
const int M=N*N;
//注意n是拆点后的大小 即 n <<= 1 N为点数(注意要翻倍) M为边数 i&1=0为i真 i&1=1为i假
struct Edge
{
int to, nex;
}edge[M];
//注意 N M 要修改
int head[N], edgenum;
void addedge(int u, int v)
{
Edge E={v, head[u]};
edge[edgenum]=E;
head[u]=edgenum++;
} bool mark[N];
int Stack[N], top;
void init()
{
memset(head, -, sizeof(head));
edgenum=;
memset(mark, , sizeof(mark));
} bool dfs(int x)
{
if(mark[x^])
return false;//一定是拆点的点先判断
if(mark[x])
return true;
mark[x]=true;
Stack[top++]=x;
for(int i=head[x];i!=-;i=edge[i].nex)
if(!dfs(edge[i].to))
return false;
return true;
} bool solve(int n)
{
for(int i=;i<n;i+=)
if(!mark[i] && !mark[i^])
{
top=;
if(!dfs(i))
{
while(top)
mark[Stack[--top]]=false;
if(!dfs(i^))
return false;
}
}
return true;
} PI a[];
double dis(PI a, PI b)
{
return sqrt((a.first-b.first)*(a.first-b.first)+(a.second-b.second)*(a.second-b.second));
} int main()
{
int n;
while(~scanf("%d", &n))
{
for(int i=;i<n;i++)
{
double x1, y1, x2, y2;
scanf("%lf%lf%lf%lf", &x1, &y1, &x2, &y2);
a[i*]=make_pair(x1, y1);
a[i*+]=make_pair(x2, y2);
}
double l=, r=;
while(r-l>=eps)
{
double m=(l+r)/2.0;
init();
for(int i=;i<n*;i++)
for(int j=i++!(i&);j<*n;j++)
if(dis(a[i], a[j])<*m)
{
addedge(i, j^);
addedge(j, i^);
}
if(solve(n*))
l=m;
else
r=m;
}
printf("%.2f\n", r);
}
return ;
}
HDOJ 3622
[2-sat]HDOJ3622 Bomb Game的更多相关文章
- [暑假集训--数位dp]hdu3555 Bomb
The counter-terrorists found a time bomb in the dust. But this time the terrorists improve on the ti ...
- 2 - sat 模板(自用)
2-sat一个变量两种状态符合条件的状态建边找强连通,两两成立1 - n 为第一状态(n + 1) - (n + n) 为第二状态 例题模板 链接一 POJ 3207 Ikki's Story IV ...
- HDU3555 Bomb[数位DP]
Bomb Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/65536 K (Java/Others)Total Submi ...
- 多边形碰撞 -- SAT方法
检测凸多边形碰撞的一种简单的方法是SAT(Separating Axis Theorem),即分离轴定理. 原理:将多边形投影到一条向量上,看这两个多边形的投影是否重叠.如果不重叠,则认为这两个多边形 ...
- Leetcode: Bomb Enemy
Given a 2D grid, each cell is either a wall 'W', an enemy 'E' or empty '0' (the number zero), return ...
- HDU 5934 Bomb(炸弹)
p.MsoNormal { margin: 0pt; margin-bottom: .0001pt; text-align: justify; font-family: Calibri; font-s ...
- hdu 3622 Bomb Game(二分+2-SAT)
Bomb Game Time Limit: 10000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...
- Bomb
Description The counter-terrorists found a time bomb in the dust. But this time the terrorists impro ...
- CF 363B One Bomb(枚举)
题目链接: 传送门 One Bomb time limit per test:1 second memory limit per test:256 megabytes Description ...
随机推荐
- ADO.NET笔记——使用通用数据访问
相关知识: 前面所有示例,君是访问特定的数据库(SQL Server),因此注入SqlConnection.SqlCommand.SqlDataReader.SqlDataAdapter等类名都添加了 ...
- linux terminal 日常shell
1 ubuntu中如何将终端添加到右键 /home/cui/.local/share/nautilus/scripts #!/bin/bash #cd $NAUTILUS_SCRIPT_CURRENT ...
- android Timer and TImerTask
android Timer and TImerTask Caused by: java.lang.IllegalStateException: TimerTask is scheduled alrea ...
- javascript中的光标
最近项目中要做一个键盘操作,光标移动的功能:增强用户体验:问朋友查资料了解到这方面的知识:整理备忘: 1.IE使用textRange对象,其他使用selectionStart selectionEnd ...
- 【Qt】Qt之自定义界面(添加自定义标题栏)【转】
简述 通过上节内容,我们实现了自定义窗体的移动,但是我们缺少一个标题栏来显示窗体的图标.标题,以及控制窗体最小化.最大化.关闭的按钮. 自定义标题栏后,所有的控件我们都可以定制,比如:在标题栏中添加换 ...
- jquery.min.map详见
温故而知新,翻出来阮前辈的文章记录一下 日期:2013年1月23日 上周,jQuery 1.9发布. 这是2.0版之前的最后一个新版本,有很多新功能,其中一个就是支持Source Map. 访问 ht ...
- Ubuntu14.04忘记root密码的解决方法
电脑20多天没用忘记密码了,下面是在网上找到的一个解决办法,其它的和这个也大概相同.因为其中有些缺漏,没能给我解决问题.通过分析最终问题还是解决了,现解决方案的关键点记录一下.希望能方便到其它人. 1 ...
- php 获取数组第一个值的方法分享
以下是对使用php实现获取数组第一个值的方法进行了详细的分析介绍,需要的朋友可以过来参考下 reset (PHP 3, PHP 4, PHP 5)reset -- 将数组的内部指针指向第一个单元 说明 ...
- Google Chrome七大新特性
Google Chrome 在日常生活中扮演的角色不只是一个功能强大的网络浏览器,它内置的 DevTools 同样也是网络开发者进行网络开发的重要工具. DevTools 在不断的进行版本更新,其中有 ...
- Demo学习: Basic jQuery
UniGUI是一套基于ExtJS的Delphi的WEB框架,它是使用ExtPascal来转化到ExtJS,ExtJS是一个跨浏览器的JavaScript库,因此UniGUI发布出来的程序可以在各种浏览 ...