zoj 3717 - Balloon(2-SAT)
裸的2-SAT,详见刘汝佳训练指南P-323
不过此题有个特别需要注意的地方:You should promise that there is still no overlap for any two balloons after rounded.
模版题,
代码如下:
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <cmath>
#include <queue>
#include <stack>
#include <vector>
#include <map> #define LL long long
#define eps 1e-5
#define M 205
#define mod 1000000007 using namespace std; struct Point
{
int x, y, z;
Point() { }
Point(int x, int y, int z) : x(x), y(y), z(z) { }
void readPoint()
{
scanf("%d %d %d", &x, &y, &z);
}
};
struct TwoSAT
{
int n;
vector<int>G[M*2];
bool mark[M*2];
int S[M*2], c; bool dfs(int x)
{
if(mark[x^1]) return false;
if(mark[x]) return true;
mark[x] = true;
S[c++] = x;
for(int i = 0; i < (int)G[x].size(); ++i)
if(!dfs(G[x][i])) return false;
return true;
} void init(int n)
{
this->n = n;
for(int i = 0; i < n*2; ++i) G[i].clear();
memset(mark, 0, sizeof(mark));
} void add_clause(int x, int y)
{
G[x^1].push_back(y);
G[y^1].push_back(x);
} bool solve()
{
for(int i = 0; i < n*2; i+=2)
if(!mark[i] && !mark[i+1])
{
c = 0;
if(!dfs(i))
{
while(c>0) mark[S[--c]] = false;
if(!dfs(i+1)) return false;
}
}
return true;
}
};
Point poi[2*M];
int dcmp(double a)
{
if(fabs(a)<eps) return 0;
return a<0?-1:1;
}
double dis(Point a, Point b)
{
return sqrt(1.0*(a.x-b.x)*(a.x-b.x)+1.0*(a.y-b.y)*(a.y-b.y)+1.0*(a.z-b.z)*(a.z-b.z));
}
int ok(int n, double R)
{
TwoSAT temp;
temp.init(n);
for(int i = 0; i < 2*n; ++i)
for(int j = i+1; j < 2*n; ++j)
if(dcmp(dis(poi[i], poi[j])-2*R)<0)
{
temp.add_clause(i^1, j^1);
}
return temp.solve();
}
int main ()
{
int n;
while(~scanf("%d", &n))
{
for(int i = 0; i < 2*n; ++i)
poi[i].readPoint();
double l = 0.0, r = dis(Point(0,0,0), Point(10000,10000,10000)), mid;
while(r-l>eps)
{
mid = (r+l)/2;
if(ok(n, mid))
l = mid;
else
r = mid;
}
double ans = (int)(mid*1000+0.5)/1000.0;//注意!!!
if(!ok(n, ans)) ans-=0.001;
printf("%.3lf\n", ans);
}
return 0;
}
zoj 3717 - Balloon(2-SAT)的更多相关文章
- ZOJ 3717 Balloon ( TLE )
正解2-SAT. 我用DLX想搜一搜的,结果TLE了…… 没什么遗憾,最起码我尝试过了. 扔个代码留作纪念. #include <cstdio> #include <cstring& ...
- ZOJ 3717
这题是二分+2SAT. 总结一下SAT题的特征.首先,可能会存在二选一的情况,然后会给出一些矛盾.据这些矛盾加边,再用SAT判定. 这一道题好像不能直接用printf("%0.3lf&quo ...
- zoj 3981 Balloon Robot
https://vjudge.net/problem/ZOJ-3981 题意: 有m个座位,其中n个队伍坐在这些位置上,一个队伍一个座位.当一个队A了题之后,他们们会得到气球,假设他们在a时刻A题,但 ...
- ZOJ 3717 二分+2-sat判定。
好久没有2-sat了,此题当复习之用,二分求最大值+2-sat判断可行,此题主要跪于题意:The results should be rounded to three decimal places. ...
- ZOJ - 3981 - Balloon Robot (思维)
参考自:https://blog.csdn.net/qq_36553623/article/details/78445558 题意: 第一行三个数字n, m, q表示有m个座位围成一个环,n个队伍,q ...
- ZOJ 3981 && 2017CCPC秦皇岛 A:Balloon Robot(思维题)
A - Balloon Robot Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%lld & %llu Sub ...
- zoj 2104 Let the Balloon Rise(map映照容器的应用)
题目链接: http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=2104 题目描述: Contest time again! Ho ...
- zoj 2104 Let the Balloon Rise
Let the Balloon Rise Time Limit: 2 Seconds Memory Limit: 65536 KB Contest time again! How excit ...
- [ZOJ 1003] Crashing Balloon (dfs搜索)
题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=3 题目大意:给你a,b两个数,问当b由约数1到100组成时,a能否由其 ...
随机推荐
- x-requested-with 请求头 区分ajax请求还是普通请求(转)
在服务器端判断request来自Ajax请求(异步)还是传统请求(同步): 两种请求在请求的Header不同,Ajax 异步请求比传统的同步请求多了一个头参数 1.传统同步请求参数 accept t ...
- SQLserver聚集表、堆和索引
SQL Server 表使用下列两种方法之一来组织其分区中的数据页: 聚集表是有聚集索引的表.数据行基于聚集索引键按顺序存储.聚集索引按 B 树索引结构实现,B 树索引结构支持基于聚集索引键值对行进行 ...
- javascript学习第四课函数
函数也是一种数据类型:function类型 所以函数也可当作一个数据作参数传递 三种函数的声明示例: 一般来讲,声明方式一和声明方式二比较常用,方式三比较少. 常用函数方式示例: 注意:虽然函数支持嵌 ...
- ms sql server 在cmd中执行sqlcmd的时候报错
cmd下直接输入sqlcmd会提示 错误: HResult 0x2,级别 16,状态 1命名管道提供程序: 无法打开与 SQL Server 的连接 [2].Sqlcmd: 错误: Microsoft ...
- 《笨办法学C》笔记之Makefile
使用gcc编译C语言源码 在Linux系统中,C语言源码需要用gcc编译为二进制可执行文件,才能够运行. $ gcc test.c -o test 这句命令就将test.c文件编译为test二进制可执 ...
- ubuntu与win10互换硬盘
实例:将sdb上的ubuntu转移至sda,将sda上的win转移至sdb1. 备份资料2. 制作老毛桃PE盘3. 格式化sda4. dd if=/dev/sdb of=/dev/sda ,将sdb克 ...
- 收藏的 500多个开源的Git源码
由dkhamsing发起的Open-Source iOS Apps收集了各种开源的iOS App,并进行了详细的分类,比如游戏.社交.健康.键盘.定位.多媒体.新闻.办公.安全以及小工具类等.截至目前 ...
- 【转】MySQL的各种timeout
因为最近遇到一些超时的问题,正好就把所有的timeout参数都理一遍,首先数据库里查一下看有哪些超时: root@localhost : test 12:55:50> show global v ...
- css高度自适应
何为高度自适应? 高度自适应就是高度能跟随浏览器窗口的大小改变而改变,典型的运用在一些后台界面中上面一栏高度固定用作菜单栏或导航栏,下面一栏高度自适应用于显示内容.高度自适应不像宽度自适应那样简单,在 ...
- ros学习笔记 - 深度传感器转换成激光数据(hector_slam)
前提条件:1,确保读者已经安装了kinect或者其他深度摄像头的驱动,如果未安装,可以直接在网盘下载:http://pan.baidu.com/s/1hqHB10w 提取密码:wrmn 利用深度相机仿 ...