裸的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. EXCEL拼接SQL

    =CONCATENATE("insert into 表名 (字段名1,字段名2)values (3,  '"&C3&"');") 用CONCAT ...

  2. iOS 自带二维码扫描功能的实现

    自从iOS7以后中新增了二维码扫描功能.因此可以在不借助第三方类库的情况下简单的写出二维码的扫描功能: 原生的二维码扫描功能在AVFoundation框架下,所以在使用原生的二维码扫描功能时要先导入A ...

  3. Bug集

    1. Spring MVC 双请求问题 viewresolver一定要放在servlet-dispatcher.xml里,否则会导致在请求成功后以后渲染页面,然后又发一次请求的状况,最后导致页面无法显 ...

  4. 用OMT方法建立其分析模型: 本大学基于网络的课程注册系统。

    OMT方法是用3种模型来描述软件系统,分别是对象模型,动态模型,功能模型. 1)对象模型:课程网络注册系统 2)动态模型:序列图 3)功能模型:数据流图 0层DFD图 1层DFD图

  5. mysql中left join ,right join 以及inner join 比较

    下面是例子分析表A记录如下: aID        aNum 1           a20050111 2           a20050112 3           a20050113 4   ...

  6. 【环境配置】php5.5 + apache2.4 安装配置【转+修改】

    转自 http://my.oschina.net/lilinzero/blog/180509 [转+修改][环境配置]php5.5.10 + apache2.4 安装配置 根据自己的实践所得,稍微修改 ...

  7. css 3 动画

    1.transition,其作用是:平滑的改变CSS的值.无论是点击事件,焦点事件,还是鼠标hover,只要值改变了,就是平滑的,就是动画. transition 属性介绍: transition-p ...

  8. ARM11 S3C6410 硬件浮点(VFP)实现

    http://blog.csdn.net/liujia2100/article/details/7459683 在调试一个代码时,编译能顺利编过.可是,就是不能执行.找了半天才发现,原来是浮点问题.由 ...

  9. CVTE实习面经

    一个月的实习都结束了,我才把这篇面经放出来...可能有记得不太清楚的地方,还请多多见谅. 第一次面试是在5月中旬. 这次面试问的主要是基础的问题吧,就是C和C++的基础问题,我记得有问到下面几个问题 ...

  10. java单例模式实现方式

    Singleton 模式要求一个类有且仅有一个实例,并提供一个全局访问点. Singleton模式 是一种职责型模式.因为我们创建了一个对象,这个对象扮演了独一无二的角色,在这个单独的对象实例中,它集 ...