【HDU】3622 Bomb Game(2-SAT)
http://acm.hdu.edu.cn/showproblem.php?pid=3622
又是各种逗。。
2-SAT是一种二元约束,每个点可以置于两种状态,但只能处于一种状态,然后图是否有解就是2-SAT啦。
看白书吧。
这个图的边的概念一定要弄懂!以下的x'表示x的另一个点
边(x, y)表示取了x就一定取y,x是前提条件!
对于约束(x, y),取x但不取y,那么显然连边(x, y'), (y, x'),这个意思一定要懂,就是说取了x就取y的另一个,可以唯一确定;那么反之取了y就一定取x的另一个(这里一定不是(x', y),因为x'是由y决定而不是y由x'决定)=
upd:我不知道前边在说什么,,,其实很简单的,对于两个状态x和y,假设我们要满足(x=1 或 y=0),那么显然当x=0时要满足这个性质,那么y只能=0。反之亦然。所以就是连边x0->y0, y1->x1。这题也是同理,对于状态x和y,如果x1和y1不能撮合,那么就连边x0->y1, y0->x1,这是因为我们必须要满足取一个,即(x=1 或 y=1),至少取一个,那么当x=0时,就只能连y1,(当然不考虑x0和y1冲突,因为我们分两次建图。。。如果到最后冲突,说明无解)
sigh..
这篇博文讲得十分详细orz http://www.cnblogs.com/kuangbin/archive/2012/10/05/2712429.html
白书上写的是dfs求,还有一种是tarjan缩点求。。
我暂时写白书的。。
本题只要二分半径然后连边即可。
#include <cstdio>
#include <cstring>
#include <cmath>
#include <string>
#include <iostream>
#include <algorithm>
#include <queue>
using namespace std;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define for1(i,a,n) for(int i=(a);i<=(n);++i)
#define for2(i,a,n) for(int i=(a);i<(n);++i)
#define for3(i,a,n) for(int i=(a);i>=(n);--i)
#define for4(i,a,n) for(int i=(a);i>(n);--i)
#define CC(i,a) memset(i,a,sizeof(i))
#define read(a) a=getint()
#define print(a) printf("%d", a)
#define dbg(x) cout << (#x) << " = " << (x) << endl
#define printarr2(a, b, c) for1(_, 1, b) { for1(__, 1, c) cout << a[_][__]; cout << endl; }
#define printarr1(a, b) for1(_, 1, b) cout << a[_] << '\t'; cout << endl
inline const int getint() { int r=0, k=1; char c=getchar(); for(; c<'0'||c>'9'; c=getchar()) if(c=='-') k=-1; for(; c>='0'&&c<='9'; c=getchar()) r=r*10+c-'0'; return k*r; }
inline const int max(const int &a, const int &b) { return a>b?a:b; }
inline const int min(const int &a, const int &b) { return a<b?a:b; } const int N=215;
const double eps=1e-4;
int n, nn, x[N], y[N], vis[N], s[N], ihead[N], cnt, top;
struct ED { int to, next; }e[(N*N)<<1];
void add(int u, int v) { e[++cnt].next=ihead[u]; ihead[u]=cnt; e[cnt].to=v; }
bool dfs(int u) {
if(vis[u]) return true;
if(vis[u^1]) return false;
vis[u]=true; s[++top]=u;
for(int i=ihead[u]; i; i=e[i].next) if(!dfs(e[i].to)) return false;
return true;
}
bool check(double r) {
CC(ihead, 0); cnt=0; CC(vis, 0);
double dis=(r*r)*4;
for1(i, 2, nn) {
int t; if(i&1) t=i+1; else t=i+2;
for1(j, t, nn) {
double x1=x[i], y1=y[i], x2=x[j], y2=y[j];
double rg=(x1-x2)*(x1-x2)+(y1-y2)*(y1-y2);
if(rg<dis) add(i, j^1), add(j, i^1);
}
}
for(int i=2; i<nn; i+=2) if(!vis[i] && !vis[i+1]) {
top=0;
if(!dfs(i)) {
while(top) vis[s[top--]]=0;
if(!dfs(i+1)) return false;
}
}
return true;
} int main() {
while(~scanf("%d", &n)) {
for1(i, 1, n) rep(j, 2) read(x[(i<<1)+j]), read(y[(i<<1)+j]); nn=(n<<1)+1;
double l=0, r=50000;
while(r-l>eps) {
double m=(l+r)/2;
if(check(m)) l=m;
else r=m;
}
printf("%.2lf\n", l);
}
return 0;
}
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.
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].
one float number for each test case, indicating the best possible
score. The result should be rounded to two decimal places.
1 1 1 -1
-1 -1 -1 1
2
1 1 -1 -1
1 -1 -1 1
1.00
【HDU】3622 Bomb Game(2-SAT)的更多相关文章
- 【HDU】I love sneakers!(分组背包)
看了许多的题解,都有题目翻译,很不错,以后我也这样写.直接翻译样例: /*鞋子的数量N[1, 100]; 拥有的金钱M[1, 1w]; 品牌数目[1, 10]*/ /*以下四行是对于每双鞋的描述*/ ...
- 【HDU】5248-序列变换(贪心+二分)
二分枚举长度改变的长度即可了 #include<cstdio> #include<cstring> #include<algorithm> using namesp ...
- 【HDU】2222 Keywords Search(AC自动机)
题目 传送门:QWQ 分析 $ AC $自动机模板,黈力的码风真的棒极了,这是我抄他的. 还有 题号不错 代码 #include <cstdio> #include <cstring ...
- 【HDU】1520 Anniversary party(树形dp)
题目 题目 分析 带权值的树上最大独立集 代码 #include <bits/stdc++.h> using namespace std; ; int a[maxn], n, fa[max ...
- 【HDU1693】Eat the Trees(插头dp)
[HDU1693]Eat the Trees(插头dp) 题面 HDU Vjudge 大概就是网格图上有些点不能走,现在要找到若干条不相交的哈密顿回路使得所有格子都恰好被走过一遍. 题解 这题的弱化版 ...
- SSAS系列——【07】多维数据(查询Cube)
原文:SSAS系列——[07]多维数据(查询Cube) 1.什么是MDX? MDX叫做"多维表达式",是一种查询语言,是一种和SQL类似的查询语言,它基于 XML for Anal ...
- SSAS系列——【06】多维数据(创建Cube)
原文:SSAS系列--[06]多维数据(创建Cube) 1.文件类型说明 项目定义文件 (.dwproj).项目用户设置 (.dwproj.user).数据源文件 (.ds).数据源视图文件 (.ds ...
- SSAS系列——【04】多维数据(物理体系结构)
原文:SSAS系列——[04]多维数据(物理体系结构) 1.本地多维数据集 本地多维数据集和本地挖掘模型允许在客户端工作站与网络的连接断开时对该工作站进行分析.在与本地多维数据集进行交互时,ADMOD ...
- SSAS系列——【05】多维数据(编程体系结构)
原文:SSAS系列--[05]多维数据(编程体系结构) 1.什么是AMO? 翻译:AMO是SSAS中一个完整的管理类集合,它在Microsoft.AnalysisServices命名空间下,我们可以在 ...
随机推荐
- vlc模块间共享变量
在模块中创建变量: vlc_value_t valTemp; var_Create( p_intf, "vlc_test", VLC_VAR_STRING ); valTemp ...
- 2.4.1 用NPOI操作EXCEL关于HSSFClientAnchor(dx1,dy1,dx2,dy2,col1,row1,col2,row2)的参数
NPOI教程:http://www.cnblogs.com/atao/archive/2009/11/15/1603528.html 之所有说NPOI强大,是因为常用的Excel操作她都可以通过编程的 ...
- INV*更新物料信息
物料 PROCEDURE update_item(p_init_msg_list IN VARCHAR2 DEFAULT fnd_api.g_false, x_return_status OUT NO ...
- php 命令行方式运行时 几种传入参数的方式
1. url方式 $param = array(); if ($argc > 1) { parse_str ( $argv [1], $param ); foreach ( $param as ...
- Centos6 安装 Redis 和集群配置
Redis安装 先确认gcc和tcl已经安装 sudo yum install gcc-c++ sudo yum install tcl 解压, 编译和安装 .tar.gz /usr/src/ cd ...
- centos下node.js的安装
安装的路径我举例在home目录 1.cd /home 2.下载node.js最新版本 wget http://nodejs.org/dist/v0.10.28/node-v0.10.28.tar.gz ...
- PHP安全细节(转)
一个常见的PHP安全细则 发布时间:2012-01-09 10:18:50 来源:51cto 评论:0 点击:9 次 [字号:大 中 小] PHP本身再老版本有一些问题,比如在 php4.3. ...
- C#指南,重温基础,展望远方!(11)C#委托
委托类型表示对具有特定参数列表和返回类型的方法的引用. 通过委托,可以将方法视为可分配给变量并可作为参数传递的实体. 委托类似于其他一些语言中的函数指针概念,但与函数指针不同的是,委托不仅面向对象,还 ...
- 04-树7. Search in a Binary Search Tree (25)
04-树7. Search in a Binary Search Tree (25) 时间限制 100 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 ...
- Windows路由表配置:双网卡同时上内外网
管理员模式CMD 路由表解释 route print -4 删除默认设置 route delete 0.0.0.0 外网路由,全走无线,192.168.0.1为无线网关 route add 0.0.0 ...