裸的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)的更多相关文章

  1. ZOJ 3717 Balloon ( TLE )

    正解2-SAT. 我用DLX想搜一搜的,结果TLE了…… 没什么遗憾,最起码我尝试过了. 扔个代码留作纪念. #include <cstdio> #include <cstring& ...

  2. ZOJ 3717

    这题是二分+2SAT. 总结一下SAT题的特征.首先,可能会存在二选一的情况,然后会给出一些矛盾.据这些矛盾加边,再用SAT判定. 这一道题好像不能直接用printf("%0.3lf&quo ...

  3. zoj 3981 Balloon Robot

    https://vjudge.net/problem/ZOJ-3981 题意: 有m个座位,其中n个队伍坐在这些位置上,一个队伍一个座位.当一个队A了题之后,他们们会得到气球,假设他们在a时刻A题,但 ...

  4. ZOJ 3717 二分+2-sat判定。

    好久没有2-sat了,此题当复习之用,二分求最大值+2-sat判断可行,此题主要跪于题意:The results should be rounded to three decimal places. ...

  5. ZOJ - 3981 - Balloon Robot (思维)

    参考自:https://blog.csdn.net/qq_36553623/article/details/78445558 题意: 第一行三个数字n, m, q表示有m个座位围成一个环,n个队伍,q ...

  6. ZOJ 3981 && 2017CCPC秦皇岛 A:Balloon Robot(思维题)

    A - Balloon Robot Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%lld & %llu Sub ...

  7. zoj 2104 Let the Balloon Rise(map映照容器的应用)

    题目链接: http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=2104 题目描述: Contest time again! Ho ...

  8. zoj 2104 Let the Balloon Rise

    Let the Balloon Rise Time Limit: 2 Seconds      Memory Limit: 65536 KB Contest time again! How excit ...

  9. [ZOJ 1003] Crashing Balloon (dfs搜索)

    题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=3 题目大意:给你a,b两个数,问当b由约数1到100组成时,a能否由其 ...

随机推荐

  1. Eclipse:Dubug快捷键

    Debug快捷键 F5单步调试进入函数内部.   F6单步调试不进入函数内部,如果装了金山词霸2006则要把"取词开关"的快捷键改成其他的.   F7由函数内部返回到调用处.   ...

  2. Coursera Machine Learning: Regression 证书

  3. 合并两个排好序的链表(c++)

    #include<iostream> struct node{ int payload; node* next; node(int payload){this->payload=pa ...

  4. Java中List,ArrayList、Vector,map,HashTable,HashMap区别用法

    Java中List,ArrayList.Vector,map,HashTable,HashMap区别用法 标签: vectorhashmaplistjavaiteratorinteger ArrayL ...

  5. Codeforces 734E. Anton and Tree 搜索

    E. Anton and Tree time limit per test: 3 seconds memory limit per test :256 megabytes input:standard ...

  6. 漫谈Linux内核哈希表(2)

    对照前面介绍过的内核通知链.链表,本章我们将要介绍的哈希表的初始化和定义也是如出一辙的: 点击(此处)折叠或打开 定义并初始化一个名为name的哈希链表表头 #define HLIST_HEAD(na ...

  7. rdlc报表大小设置

    参考:http://stackoverflow.com/questions/427730/how-to-limit-rdlc-report-for-one-page-in-a-pdf 主要设置为:报表 ...

  8. [转]centos6.6 rpm安装与管理

    centos6.6 rpm安装与管理 原文地址:http://www.centoscn.com/CentOS/2015/0414/5182.html   rpm包管理:安装.升级.卸载.查询.检验 安 ...

  9. 手机safari图片上传竖变横处理

    在手机safari上传图片时,竖着的照片会变成横着的照片,以下程序片段利用图片exif信息把图片旋转回去,代码抄自php.net官网. http://php.net/manual/zh/functio ...

  10. Android数据库安全解决方案,使用SQLCipher进行加解密

    转载请注明出处:http://blog.csdn.net/guolin_blog/article/details/11952409 我们都知道,Android系统内置了SQLite数据库,并且提供了一 ...