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能否由其 ...
随机推荐
- oracle exp imp 导入 正在跳过表 plsql 导入表 成功终止 数据 被导入
http://blog.csdn.net/agileclipse/article/details/12968011 .导入过程中,所有表导入都出现提示, 正在跳过表...某某表名 最后提示成功终止导入 ...
- Dijkstra搜索算法
Dijkstra无向图 算法执行步骤如下: 上面两张图来源于:http://blog.csdn.net/v_july_v/article/details/6096981 很牛的大神,膜拜,此处有鲜花 ...
- JS浮点数的加减乘除运算
文章来源地址:http://blog.csdn.net/lyd518/article/details/7236464 转载请注明出处,尊重作者劳动成果,谢谢!问题这样的: 37.5*5.5=206.0 ...
- JavaWeb 学习001-登录页面
首先实现一个web应用的登录页面 1.遇到的问题: Servlet中 post 或者 get 方式 不能提交? 就是提交后,控制台没有反应,而且浏览器显示如图: 这样应该是不能进行页面的跳转,对这个, ...
- hadoop-mongo map/reduce java
官方 http://docs.mongodb.org/ecosystem/tutorial/getting-started-with-hadoop/ mongo-haoop项目地址 https://g ...
- UIView中间透明周围半透明(四种方法)
方法一 #import "DrawView.h" @implementation DrawView - (instancetype)initWithFrame:(CGRect)fr ...
- sql学习
1.改变表的某一字段的长度: alter table tt modify a char(2000); 2.不想打开表就查看某一字段的长度可用下面的方法: select length(a),leng ...
- 为什么Smalltalk不流行
最近读到一本书,说Python程序员比Java程序员聪明.同理,懂Smalltalk的程序员也比Java程序员聪明.所以,我在StackOverflow上找到这个关闭很久的问题,整理了一下,跟大家分享 ...
- java中获取路径的几种方式
总是忘记, 备份一下,方便下次用. 第一种: File directory = new File("");//参数为空 String courseFile = directory. ...
- 纯jsp用户登录系统
用纯jsp技术实现用户登录系统,需要用到三个.jsp文件.在文本目录下新建三个.jsp文件,分别命名为login.jsp,logincl.jsp和wel.jsp. 1.login.jsp文件用来放界面 ...