裸的2-SAT,详见刘汝佳训练指南P-323

不过此题有个特别需要注意的地方:You should promise that there is still no overlap for any two balloons after rounded.

模版题,

代码如下:

  1. #include <cstdio>
  2. #include <cstring>
  3. #include <cstdlib>
  4. #include <algorithm>
  5. #include <string>
  6. #include <cmath>
  7. #include <queue>
  8. #include <stack>
  9. #include <vector>
  10. #include <map>
  11.  
  12. #define LL long long
  13. #define eps 1e-5
  14. #define M 205
  15. #define mod 1000000007
  16.  
  17. using namespace std;
  18.  
  19. struct Point
  20. {
  21. int x, y, z;
  22. Point() { }
  23. Point(int x, int y, int z) : x(x), y(y), z(z) { }
  24. void readPoint()
  25. {
  26. scanf("%d %d %d", &x, &y, &z);
  27. }
  28. };
  29. struct TwoSAT
  30. {
  31. int n;
  32. vector<int>G[M*2];
  33. bool mark[M*2];
  34. int S[M*2], c;
  35.  
  36. bool dfs(int x)
  37. {
  38. if(mark[x^1]) return false;
  39. if(mark[x]) return true;
  40. mark[x] = true;
  41. S[c++] = x;
  42. for(int i = 0; i < (int)G[x].size(); ++i)
  43. if(!dfs(G[x][i])) return false;
  44. return true;
  45. }
  46.  
  47. void init(int n)
  48. {
  49. this->n = n;
  50. for(int i = 0; i < n*2; ++i) G[i].clear();
  51. memset(mark, 0, sizeof(mark));
  52. }
  53.  
  54. void add_clause(int x, int y)
  55. {
  56. G[x^1].push_back(y);
  57. G[y^1].push_back(x);
  58. }
  59.  
  60. bool solve()
  61. {
  62. for(int i = 0; i < n*2; i+=2)
  63. if(!mark[i] && !mark[i+1])
  64. {
  65. c = 0;
  66. if(!dfs(i))
  67. {
  68. while(c>0) mark[S[--c]] = false;
  69. if(!dfs(i+1)) return false;
  70. }
  71. }
  72. return true;
  73. }
  74. };
  75. Point poi[2*M];
  76. int dcmp(double a)
  77. {
  78. if(fabs(a)<eps) return 0;
  79. return a<0?-1:1;
  80. }
  81. double dis(Point a, Point b)
  82. {
  83. 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));
  84. }
  85. int ok(int n, double R)
  86. {
  87. TwoSAT temp;
  88. temp.init(n);
  89. for(int i = 0; i < 2*n; ++i)
  90. for(int j = i+1; j < 2*n; ++j)
  91. if(dcmp(dis(poi[i], poi[j])-2*R)<0)
  92. {
  93. temp.add_clause(i^1, j^1);
  94. }
  95. return temp.solve();
  96. }
  97. int main ()
  98. {
  99. int n;
  100. while(~scanf("%d", &n))
  101. {
  102. for(int i = 0; i < 2*n; ++i)
  103. poi[i].readPoint();
  104. double l = 0.0, r = dis(Point(0,0,0), Point(10000,10000,10000)), mid;
  105. while(r-l>eps)
  106. {
  107. mid = (r+l)/2;
  108. if(ok(n, mid))
  109. l = mid;
  110. else
  111. r = mid;
  112. }
  113. double ans = (int)(mid*1000+0.5)/1000.0;//注意!!!
  114. if(!ok(n, ans)) ans-=0.001;
  115. printf("%.3lf\n", ans);
  116. }
  117. return 0;
  118. }

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. oracle exp imp 导入 正在跳过表 plsql 导入表 成功终止 数据 被导入

    http://blog.csdn.net/agileclipse/article/details/12968011 .导入过程中,所有表导入都出现提示, 正在跳过表...某某表名 最后提示成功终止导入 ...

  2. Dijkstra搜索算法

    Dijkstra无向图 算法执行步骤如下: 上面两张图来源于:http://blog.csdn.net/v_july_v/article/details/6096981 很牛的大神,膜拜,此处有鲜花 ...

  3. JS浮点数的加减乘除运算

    文章来源地址:http://blog.csdn.net/lyd518/article/details/7236464 转载请注明出处,尊重作者劳动成果,谢谢!问题这样的: 37.5*5.5=206.0 ...

  4. JavaWeb 学习001-登录页面

    首先实现一个web应用的登录页面 1.遇到的问题: Servlet中 post 或者 get 方式 不能提交? 就是提交后,控制台没有反应,而且浏览器显示如图: 这样应该是不能进行页面的跳转,对这个, ...

  5. hadoop-mongo map/reduce java

    官方 http://docs.mongodb.org/ecosystem/tutorial/getting-started-with-hadoop/ mongo-haoop项目地址 https://g ...

  6. UIView中间透明周围半透明(四种方法)

    方法一 #import "DrawView.h" @implementation DrawView - (instancetype)initWithFrame:(CGRect)fr ...

  7. sql学习

    1.改变表的某一字段的长度: alter table tt   modify a char(2000); 2.不想打开表就查看某一字段的长度可用下面的方法: select length(a),leng ...

  8. 为什么Smalltalk不流行

    最近读到一本书,说Python程序员比Java程序员聪明.同理,懂Smalltalk的程序员也比Java程序员聪明.所以,我在StackOverflow上找到这个关闭很久的问题,整理了一下,跟大家分享 ...

  9. java中获取路径的几种方式

    总是忘记, 备份一下,方便下次用. 第一种: File directory = new File("");//参数为空 String courseFile = directory. ...

  10. 纯jsp用户登录系统

    用纯jsp技术实现用户登录系统,需要用到三个.jsp文件.在文本目录下新建三个.jsp文件,分别命名为login.jsp,logincl.jsp和wel.jsp. 1.login.jsp文件用来放界面 ...