这题是二分+2SAT.

总结一下SAT题的特征。首先,可能会存在二选一的情况,然后会给出一些矛盾。据这些矛盾加边,再用SAT判定。

这一道题好像不能直接用printf("%0.3lf"),因为这个是四舍五入的,这道题好像不能四舍五入,只好选减去0.0005再按这个格式输出了。

  1. #include <iostream>
  2. #include <cstdio>
  3. #include <cstring>
  4. #include <algorithm>
  5. #include <cmath>
  6. #include <stdlib.h>
  7. #define oo 1000000007
  8. #define eps 1e-4
  9. using namespace std;
  10. const int MAXN=;
  11. const int MAXM=;
  12. struct b{
  13. int x,y,z;
  14. }ball[MAXN];
  15. double dis[MAXN][MAXN];
  16. int head[MAXN],dfn[MAXN],low[MAXN],tot,stop,indx,belong[MAXN],pat;
  17. int st[MAXN];
  18. bool stack[MAXN];
  19. int n;
  20. struct e{
  21. int u,v;
  22. int next;
  23. }edge[MAXM];
  24.  
  25. void addedge(int u,int v){
  26. edge[tot].u=u;
  27. edge[tot].v=v;
  28. edge[tot].next=head[u];
  29. head[u]=tot++;
  30. }
  31.  
  32. void tarjan(int u){
  33. int v;
  34. dfn[u]=low[u]=++indx;
  35. st[stop++]=u;
  36. stack[u]=true;
  37. for (int e=head[u];e!=-;e=edge[e].next){
  38. v=edge[e].v;
  39. if (dfn[v]==) {
  40. tarjan(v) ;
  41. low[u] = min(low[u], low[v]) ;
  42. }
  43. else if (stack[v]) {
  44. low[u] = min(low[u], dfn[v]) ;
  45. }
  46. }
  47. if (dfn[u] == low[u]) {
  48. pat++;
  49. do{
  50. v = st[--stop];
  51. belong[v]=pat;
  52. stack[v]=false;
  53. }while(u!= v);
  54. }
  55. }
  56.  
  57. bool slove(double leng){
  58. int a,b; tot=; indx=; stop=; pat=-;
  59. memset(head,-,sizeof(head));
  60. for(int i=;i<n;i++){
  61. a=i;
  62. for(int j=i+;j<n;j++){
  63. b=j;
  64. if(leng*>dis[a*][b*]){
  65. addedge(*a+,b*);
  66. addedge(b*+,a*);
  67. }
  68. if(leng*>dis[a*][b*+]){
  69. addedge(a*+,b*+);
  70. addedge(b*,a*);
  71. }
  72. if(leng*>dis[a*+][b*]){
  73. addedge(a*,b*);
  74. addedge(b*+,a*+);
  75. }
  76. if(leng*>dis[a*+][b*+]){
  77. addedge(a*,b*+);
  78. addedge(b*,a*+);
  79. }
  80. }
  81. }
  82. memset(dfn,,sizeof(dfn));
  83. memset(low,,sizeof(low));
  84. memset(stack,false,sizeof(stack));
  85. memset(belong,-,sizeof(belong));
  86. for(int i=;i<*n;i++){
  87. if(dfn[i]==){
  88. tarjan(i);
  89. }
  90. }
  91. bool flag=true;
  92. for(int i=;i<n;i++){
  93. if(belong[i*]==belong[i*+]){
  94. flag=false;
  95. break;
  96. }
  97. }
  98. return flag;
  99. }
  100.  
  101. int main(){
  102. double xi,yi,zi;
  103. while(scanf("%d",&n)!=EOF){
  104. for(int i=;i<*n;i++){
  105. scanf("%d%d%d",&ball[i].x,&ball[i].y,&ball[i].z);
  106. i++;
  107. scanf("%d%d%d",&ball[i].x,&ball[i].y,&ball[i].z);
  108. }
  109. double high=oo,lown=; double tmp;
  110. for(int i=;i<*n;i++){
  111. for(int j=i;j<*n;j++){
  112. xi=ball[i].x-ball[j].x;
  113. yi=ball[i].y-ball[j].y;
  114. zi=ball[i].z-ball[j].z;
  115. tmp=sqrt(xi*xi+yi*yi+zi*zi);
  116. dis[i][j]=dis[j][i]=tmp;
  117. }
  118. }
  119. double ans;
  120. while(lown<high-eps){
  121. double mid=(high+lown)/;
  122. if(slove(mid)){
  123. ans=mid;
  124. lown=mid;
  125. }
  126. else high=mid;
  127. }
  128. printf("%0.3lf\n",ans-0.0005);
  129. }
  130. return ;
  131. }

ZOJ 3717的更多相关文章

  1. zoj 3717 - Balloon(2-SAT)

    裸的2-SAT,详见刘汝佳训练指南P-323 不过此题有个特别需要注意的地方:You should promise that there is still no overlap for any two ...

  2. ZOJ 3717 Balloon ( TLE )

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

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

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

  4. ZOJ People Counting

    第十三届浙江省大学生程序设计竞赛 I 题, 一道模拟题. ZOJ  3944http://www.icpc.moe/onlinejudge/showProblem.do?problemCode=394 ...

  5. ZOJ 3686 A Simple Tree Problem

    A Simple Tree Problem Time Limit: 3 Seconds      Memory Limit: 65536 KB Given a rooted tree, each no ...

  6. ZOJ Problem Set - 1394 Polar Explorer

    这道题目还是简单的,但是自己WA了好几次,总结下: 1.对输入的总结,加上上次ZOJ Problem Set - 1334 Basically Speaking ac代码及总结这道题目的总结 题目要求 ...

  7. ZOJ Problem Set - 1392 The Hardest Problem Ever

    放了一个长长的暑假,可能是这辈子最后一个这么长的暑假了吧,呵呵...今天来实验室了,先找了zoj上面简单的题目练练手直接贴代码了,不解释,就是一道简单的密文转换问题: #include <std ...

  8. ZOJ Problem Set - 1049 I Think I Need a Houseboat

    这道题目说白了是一道平面几何的数学问题,重在理解题目的意思: 题目说,弗雷德想买地盖房养老,但是土地每年会被密西西比河淹掉一部分,而且经调查是以半圆形的方式淹没的,每年淹没50平方英里,以初始水岸线为 ...

  9. ZOJ Problem Set - 1006 Do the Untwist

    今天在ZOJ上做了道很简单的题目是关于加密解密问题的,此题的关键点就在于求余的逆运算: 比如假设都是正整数 A=(B-C)%D 则 B - C = D*n + A 其中 A < D 移项 B = ...

随机推荐

  1. Autobiography

    Autobiography My name is Donggongdechen. I am ** years old. I was born in XuChang, HeNan province, t ...

  2. Java压缩技术(二) ZIP压缩——Java原生实现

    原文:http://snowolf.iteye.com/blog/642298 去年整理了一篇ZLib算法Java实现(Java压缩技术(一) ZLib),一直惦记却没时间补充.今天得空,整理一下ZI ...

  3. go之for循环

    一.基于计数器的迭代 格式 for 初始化语句; 条件语句; 修饰语句{} 实例 package main import "fmt" func main(){ for i:=0;i ...

  4. CentOS7 搭建Kafka(三)工具篇

    CentOS7 搭建Kafka(三)工具篇 做为一名懒人,自然不喜欢敲那些命令,一个是容易出错,另外一个是懒得记,能有个工具就最好了,一查还挺多,我们用个最主流的Kafka Manager Kafka ...

  5. CORS 和 JSONP

    跨域资源共享(CORS) 它允许浏览器向跨源服务器,发出XMLHttpRequest请求,从而克服了AJAX只能同源使用的限制. CORS(Cross-Origin Resource Sharing) ...

  6. Android6.0以上版本获取本机蓝牙地址

    Android6.0以上版本使用BluetoothAdapter.getDefaultAdapter().getAddress()是获取不到正确的蓝牙地址的,返回的值都是02:00:00:00:00: ...

  7. Leetcode0037--Sudoku Solver 数独游戏

    [转载请注明]http://www.cnblogs.com/igoslly/p/8719622.html 来看一下题目: Write a program to solve a Sudoku puzzl ...

  8. Sql语句优化-查询两表不同行NOT IN、NOT EXISTS、连接查询Left Join

    在实际开发中,我们往往需要比较两个或多个表数据的差别,比较那些数据相同那些数据不相同,这时我们有一下三种方法可以使用:1. IN或NOT IN,2. EXIST或NOTEXIST,3.使用连接查询(i ...

  9. 基于 CC2530 的温度采集系统(未定稿)

    前言 最近在自学 Zigbee,每天的主要是任务是:看博客,看 CC2530 的 datasheet 和实践,熟悉片上的 SFR 以及控制板子. 学和做内容包括:IO.外部中断.Timer1/3/4. ...

  10. CXF-JAX-RS开发(二)spring整合CXF-JAX-RS

    一.创建maven工程[Packaging:war] 1.目录结构 2.坐标书写 二.导入依赖和tomcat服务器插件 <dependencies> <!-- CXF --> ...