[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 ...
随机推荐
- 【风马一族_Android】代码英语之二 布局文件的Android各个参数
布局文件的Android各个参数 第一类:属性值 true或者 false android:layout _center Hrizontal 水平居中 android:la ...
- ADO.NET笔记——读取二进制大对象(BLOB)
相关知识: 在SQL Server中,一般情况下,每行数据的总长度不能超过8K字节.因此,下列数据类型的长度,也不能超过8K字节:binary,char(),nchar(),varchar(),nva ...
- wordpress 在linux上配置固定url方法
wordpress 设置固定url总结 相信好多用wordpress的网友为了提升wordpress对搜索引擎的友好,或者是为了写的博客地址更好记,都会在wordpress的后台设置固定url的方式. ...
- 重拾C,一天一点点_2
类型转换一般来说,如果二元运算符的两个操作数具有不同的类型,较低的类型提升为较高类型,结果为较高类型.表达式由float类型的操作数不会自动转换为double类型.使用float类型主要是为了在使用较 ...
- apache common包下的StringUtils的join方法
apache common包下的StringUtils的join方法: 关键字:java string array join public static String join(Iterator it ...
- jquery trigger伪造a标签的click事件取代window.open方法
$(function() { $('#btnyes').click(function () { $('#ssss').attr("href", "http://www.b ...
- 关闭ios虚拟键盘的几种方法
在iOS应用开发中,有三类视图对象会打开虚拟键盘,进行输入操作,但如何关闭虚拟键盘,却没有提供自动化的方法.这个需要我们自己去实现.这三类视图对象分别是UITextField,UITextView和U ...
- (转) java 复制文件,不使用输出流复制,高效率,文件通道的方式复制文件
public static void fileChannelCopy(File s, File t) { FileInputStream fi = null; FileOutputStream fo ...
- SQL_SERVER_2008升级SQL_SERVER_2008_R2办法 (一、升级;二、重新xie载安装)
SQL_SERVER_2008升级SQL_SERVER_2008_R2两种办法 今天将由于需要就将我的SQL 2008升级到SQL 2008 R2. 说到为什么要升级是因为,因附加数据库时发现报错 ...
- internet协议
internet协议入门 前言 劳于读书,逸于作文. 原文地址:internet协议入门 博主博客地址:Damonare的个人博客 博主之前写过一篇博客:网络协议分析,在这篇博客里通过抓包,具体的分析 ...