ZOJ 3717 Balloon(2-sat)
2015-08-12 01:00
381 查看
Balloon
Time Limit: 3 Seconds Memory Limit: 65536 KB Special Judge
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 N groups 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?
each line contains six integers, indicating the coordinates of two balloons.
NOTICE: The garden only limits the center of the balloon.
for any two balloons after rounded.
Author: REN, Qing
题目:给出空间中的n对点,要求从每对点中选出一个,使得最近的点的距离最远。
题解:2-sat 模板,二分答案。
Time Limit: 3 Seconds Memory Limit: 65536 KB Special Judge
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 N groups 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 overlapfor any two balloons after rounded.
Sample Input
2 1 1 1 5 5 5 1 1 1 5 5 5
Sample Output
3.464
Author: REN, Qing
题目:给出空间中的n对点,要求从每对点中选出一个,使得最近的点的距离最远。
题解:2-sat 模板,二分答案。
#include<cstring> #include<cstdio> #include<iostream> #include<algorithm> #include<cmath> #define Mod 1000000007 #define ll long long using namespace std; const int MAXN = 1010; const int MAXM = 500010; int Low[MAXN],DFN[MAXN],Stack[MAXN],Belong[MAXN]; int Index,top; int scc,n; int head[MAXN],tot; bool Instack[MAXN]; int num[MAXN]; struct Edge { int to,next; } edge[MAXM]; struct Point { double x,y,z; } p[MAXN][2]; void init() { tot = 0; memset(head,-1,sizeof(head)); } void addedge(int u,int v) { edge[tot].to = v; edge[tot].next = head[u]; head[u] = tot++; } double dist(Point a,Point b) { return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y)+(a.z-b.z)*(a.z-b.z)); } void Tarjan(int u) { int v; Low[u] = DFN[u] = ++Index; Stack[top++] = u; Instack[u] = true; for(int i = head[u]; i != -1; i = edge[i].next) { v = edge[i].to; if( !DFN[v] ) { Tarjan(v); if(Low[u] > Low[v])Low[u] = Low[v]; } else if(Instack[v] && Low[u] > DFN[v]) Low[u] = DFN[v]; } if(Low[u] == DFN[u]) { scc++; do { v = Stack[--top]; Instack[v] = false; Belong[v] = scc; num[scc]++; } while(v != u); } } bool solve(int n) { memset(DFN,0,sizeof(DFN)); memset(Instack,false,sizeof(Instack)); memset(num,0,sizeof(num)); Index = scc = top = 0; for(int i = 0; i < n; i++) if(!DFN[i]) Tarjan(i); for(int i = 0; i < n; i += 2) { if(Belong[i] == Belong[i^1]) return false; } return true; } bool C(double R) { init(); for(int i=0; i<n; i++) { for(int j=i+1; j<n; j++) { for(int k=0; k<2; k++) { for(int l=0; l<2; l++) { if(dist(p[i][k],p[j][l])<=2*R) { addedge(i*2+k,j*2+(l^1)); addedge(j*2+l,i*2+(k^1)); } } } } } return solve(2*n); } int main() { //freopen("test.in","r",stdin); while(cin>>n) { for(int i=0; i<n; i++) { for(int j=0; j<2; j++) { scanf("%lf%lf%lf",&p[i][j].x,&p[i][j].y,&p[i][j].z); } } double l=0.0,r=1000000000000.0+1; for(int i=0; i<100; i++) { double mid=(l+r)/2; if(C(mid))l=mid; else r=mid; } printf("%.3f\n",l-0.0005); } return 0; }
相关文章推荐
- 是非常不错的或许以后
- HDOJ 1718 Rank
- HDU 5371 Hotaru's problem(Manacher算法 回文串)
- Codeforces Round #315 (Div. 2) (ABCD题)
- HDU - 2242 考研路茫茫――空调教室(树形DP+强连通分量)
- 送上一篇应付Java 面试的秘籍(Java 初级)
- 基于socket的心跳长连接
- BZOJ 2301 [HAOI2011]Problem b (容斥+莫比乌斯反演+分块优化 详解)
- xampp修改mysql的默认空密码
- HDU - 3594 Cactus(仙人掌图)
- Dijkstra算法总结
- GP规范学习(一)
- CoreData的基本使用
- ZOJ 3721 Final Exam Arrangement(贪心)
- 编译cocos2dx 工程,ndk-build 报错:
- MyEclipse6.6 汉化过程
- 在Android上面如何使用带有心跳检测的Socket
- 搭建java开发环境
- POJ 1741 Tree(树分治|ltc男人八题)
- canvas阴影