zoj 3717 2-sat
来源:互联网 发布:python帮助文档中文版 编辑:程序博客网 时间:2024/06/03 23:41
http://vjudge.net/contest/view.action?cid=48609#problem/D
Description
The weather is wonderful today. Gao takes a walk in the garden with his girlfriend. His girlfriend likes balloons so much, so that she wants to fly some balloons (not kites!) in the garden.
We can regard the garden as a three-dimensional space, and its coordinate starts from (0,0,0) to (10000,10000,10000). There are Ngroups of balloons, each of groups has a red balloon and a blue balloon. We can regard each balloon as a sphere, all the radius of spheres are R. The center of each sphere will be given in the input.
For some reasons, she wants to choose one balloon (red one or blue one) from each group, so that she can put exactly N balloons in the garden. It's obvious that there is no overlap for any two balloons in the N balloons which she selected. The largest R will make Gao's girlfriend happiest. Can you help Gao to calculate the largest R?
Input
There are multiple cases. For each case, The first line contains an integer N (2 ≤ N ≤ 200), meaning there are N groups of balloons. In the next N lines, each line contains six integers, indicating the coordinates of two balloons.
NOTICE: The garden only limits the center of the balloon.
Output
For each test case, it contains one real number indicating the largest R. The results should be rounded to three decimal places. You should promise that there is still no overlap for any two balloons after rounded.
Sample Input
21 1 1 5 5 51 1 1 5 5 5
Sample Output
3.464
#include <iostream>#include <cstdio>#include <cstring>#include <stack>#include <algorithm>#include <cmath>using namespace std;#define N 210#define eps 1e-6double x[N][2],y[N][2],z[N][2];const int maxn=505;const int maxm=100005;int n,m,a[maxm][3];struct note{ int to; int next;} edge[maxn*2*maxn];int head[maxn];int ip;int dfn[maxn],low[maxn],sccno[maxn],cnt,scc,instack[maxn];stack<int>stk;void init(){ memset(head,-1,sizeof(head)); ip=0;}void addedge(int u,int v){ edge[ip].to=v,edge[ip].next=head[u],head[u]=ip++;}// x = xval or y = yvalvoid add_cluse(int x,int xval,int y,int yval){ x=x*2+xval; y=y*2+yval; addedge(x,y^1); addedge(y,x^1);}void tarjan(int u){ dfn[u]=low[u]=++scc; stk.push(u); instack[u]=1; for (int i=head[u]; i!=-1; i=edge[i].next) { int v=edge[i].to; if (!dfn[v]) { tarjan(v); low[u]=min(low[u],low[v]); } else if (instack[v]) low[u]=min(low[u],dfn[v]); } if (low[u]==dfn[u]) { cnt++; int x; do { x=stk.top(); stk.pop(); sccno[x]=cnt; instack[x]=0; } while (x!=u); }}inline bool reach(int i,int ival,int j,int jval,double R){ return (x[i][ival]-x[j][jval])*(x[i][ival]-x[j][jval])+ (y[i][ival]-y[j][jval])*(y[i][ival]-y[j][jval])+ (z[i][ival]-z[j][jval])*(z[i][ival]-z[j][jval])<4*R*R;}bool solve(double R){ init(); for(int i=0; i<n; ++i) for(int a=0; a<2; ++a) for(int j=i+1; j<n; ++j) for(int b=0; b<2; ++b) if(reach(i,a,j,b,R)) add_cluse(i,a^1,j,b^1); // a,b can't be true at the same time, so a^1 or b^1 scc=cnt=0; memset(sccno,0,sizeof(sccno)); memset(dfn,0,sizeof(dfn)); memset(low,0,sizeof(low)); memset(instack,0,sizeof(instack)); while (!stk.empty()) stk.pop(); for (int i=0; i<2*n; i++) if (!dfn[i]) tarjan(i); for (int i=0; i<2*n; i+=2) { if (sccno[i]==sccno[i^1]) return false; } return true;}int main (){ while(scanf("%d",&n)!=EOF) { for(int i=0; i<n; ++i) { for(int k=0; k<2; ++k) scanf("%lf%lf%lf",&x[i][k],&y[i][k],&z[i][k]); } double left=0.0,right=100000.0; while(right-left>eps) { double mid=(left+right)/2; if(solve(mid)) left=mid; else right=mid; } printf("%.3lf\n",(int)(left*1000)/1000.0); } return 0;}
- zoj 3717 2-SAT
- ZOJ 3717 2-sat
- zoj 3717 2-sat
- zoj 3717 - Balloon(2-SAT)
- ZOJ 3717 Balloon (2sat+二分)
- ZOJ 3717 HDU 3622 二分+2-SAT
- zoj 3717 Balloon(二分+2-SAT)
- ZOJ 3717 2-sat 进位精度
- ZOJ 3717 二分+2-sat判定。
- ZOJ 3717 Balloon(2-sat)
- ZOJ 3422 2-SAT
- ZOJ 3717 - Balloon 简单二分+2-sat..精度恶心..
- zoj 3717 二分+2sat tarjan求强连通
- ZOJ 3656 Bit Magic (2-Sat问题)
- ZOJ 3656 Bit Magic(2-sat)
- ZOJ 3656 2-sat模板题
- ZOJ 3656 Bit Magic (2-SAT判断)
- zoj 3656 hdu 4421 (2—SAT)
- 深入理解jQuery中$.get、$.post、$.getJSON和$.ajax的用法
- UIScrollView
- 用FileOutPutStream写流文件的有效方法
- NYOJ-891 找点
- ACM:递归与分治,最大连续和,O(n3), O(n2), O(nlogn), O(n) 算法。
- zoj 3717 2-sat
- UVA 12714 Two Points Revisited(简单数学题)
- 【自动语音识别课程】第一课 统计语音识别介绍
- IsolatedStorageSettings.Save提示空间不足
- 一种排序
- C-堆和栈的区别 [2]
- 小米输掉官司,倒打一耙不如坦然认错
- 14行脚本配置Linux下Java环境变量
- iperf网络测速软件