[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 ...
随机推荐
- nginx 日志管理
日志管理 我们观察nginx的server段,可以看到如下类似信息 #access_log logs/host.access.log main; 这说明 该server, 它的访问日志的文件是 ...
- node-mongo-native1.3.19连接mongo的最优方法
最近需要在node下连接mongo,尝试了很多方法,本文简要总结一下 选择Driver 首先,基本上有4个常见的driver供选择 1.官方的是node-mongo-native 2.基于node-m ...
- laravel--为什么属性在模型中没有定义,却取出来了值,这些属性哪里来的
看laravel模型中的这段代码, public function getLimitUsersAttribute() { return $this->user_limit - $this-> ...
- WPF学习06:转换控件内容为可存储图片
在图形软件中,我们经常使用到"另存为图片"的功能,本文即介绍如何将WPF控件显示内容转换为图片. , , PixelFormats.Pbgra32); bitmapRender.R ...
- R语言基础(一) 可视化基础
##数据获取 x1=round(runif(100,min=80,max=100)) x2=round(rnorm(100,mean=80, sd=7)) x3=round(rnorm(100,mea ...
- django 更新model
修改models.py 中对应的class 在admin.py 中 增加 admin.site.register(WafDevice) 进入dbshell python manage.py dbshe ...
- JavaScript 代码片段
1.无题 if (i && i.charAt(i.length - 1) == "/") { i = i.substr(0, i.length - 1) } 2.无 ...
- 在MAC平台下编译Ngnix ,由于MD5算法不能编译通过 解决办法
近期想学习Ngnix 代码,前些日子,对”自己下手狠一次“, 买了MAC 本. 所以想在Mac 上编译,是必须的,不然对不起自己的内心. 不巧遇到了MD5算法编译的问题 src/core/ngx_cr ...
- LCA专题
标签(空格分隔): LCA 我的个人网站挂了,最近就先用这个来写博客吧.以后争取在这个网站写一些与OI无关的个人爱好的东西. 题目来源:code[VS] 倍增--在线算法 用 $f[i][j]$ 记录 ...
- css/js online online code editor/formator/debuger
http://cssdeck.com/labs http://jsfiddle.net/ http://fiddle.jshell.net/ support console http://plnkr ...