zoj3717 Balloon(二分+2SAT)
来源:互联网 发布:java数据结构编程 编辑:程序博客网 时间:2024/05/17 00:08
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 overlap for any two balloons after rounded.
Sample Input
21 1 1 5 5 51 1 1 5 5 5
Sample Output
3.464
这题其实和hdu3622这题是一个题,把那个题代码随便改改交这题也能过。只不过从二维变成了三维而已。
这题要注意的只有一个点:精度!因为求出来的答案是浮点数,保留3位小数的时候会四舍五入,所以最后输出的时候要处理一下。
详情请见代码:
#include <iostream>#include<cstdio>#include<cstring>#include<cmath>using namespace std;const int N = 405;const int M = 2000005;const double eps = 1e-4;int head[N];int scc[N];int vis[N];int stack1[N];int stack2[N];int n,num;bool flag;struct node{ int x1,y1,z1,x2,y2,z2;}pt[205];double tb[205][205][4];struct edge{ int to,next;}g[M];void init(){ memset(head,-1,sizeof(head)); memset(vis,0,sizeof(vis)); memset(scc,0,sizeof(scc)); stack1[0] = stack2[0] = num = 0; flag = true;}double dis(int x1,int y1,int z1,int x2,int y2,int z2){ return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2) + (z1 - z2) * (z1 - z2));}void maketable(){ int i,j; for(i = 1;i < n;i ++) { for(j = i + 1;j <= n;j ++) { tb[i][j][0] = dis(pt[i].x1,pt[i].y1,pt[i].z1,pt[j].x1,pt[j].y1,pt[j].z1); tb[i][j][1] = dis(pt[i].x1,pt[i].y1,pt[i].z1,pt[j].x2,pt[j].y2,pt[j].z2); tb[i][j][2] = dis(pt[i].x2,pt[i].y2,pt[i].z2,pt[j].x1,pt[j].y1,pt[j].z1); tb[i][j][3] = dis(pt[i].x2,pt[i].y2,pt[i].z2,pt[j].x2,pt[j].y2,pt[j].z2); } }}void build(int s,int e){ g[num].to = e; g[num].next = head[s]; head[s] = num ++;}void dfs(int cur,int &sig,int &cnt){ if(!flag) return; vis[cur] = ++sig; stack1[++stack1[0]] = cur; stack2[++stack2[0]] = cur; for(int i = head[cur];i != -1;i = g[i].next) { if(!vis[g[i].to]) dfs(g[i].to,sig,cnt); else { if(!scc[g[i].to]) { while(vis[stack2[stack2[0]]] > vis[g[i].to]) stack2[0] --; } } } if(stack2[stack2[0]] == cur) { stack2[0] --; ++ cnt; do { scc[stack1[stack1[0]]] = cnt; int tmp = stack1[stack1[0]]; if((tmp > n && scc[tmp - n] == cnt) || (tmp <= n && scc[tmp + n] == cnt)) { flag = false; return; } }while(stack1[stack1[0] --] != cur); }}void Gabow(){ int i,sig,cnt; sig = cnt = 0; for(i = 1;i <= n + n && flag;i ++) if(!vis[i]) dfs(i,sig,cnt);}bool twosat(double mid){ int i,j; for(i = 1;i < n;i ++) { for(j = i + 1;j <= n;j ++) { if(tb[i][j][0] - mid < eps) { build(i,j + n); build(j,i + n); } if(tb[i][j][1] - mid < eps) { build(i,j); build(j + n,i + n); } if(tb[i][j][2] - mid < eps) { build(i + n,j + n); build(j,i); } if(tb[i][j][3] - mid < eps) { build(i + n,j); build(j + n,i); } } } Gabow(); return flag;}int main(){ int i,j; while(~scanf("%d",&n)) { for(i = 1;i <= n;i ++) { scanf("%d%d%d%d%d%d",&pt[i].x1,&pt[i].y1,&pt[i].z1,&pt[i].x2,&pt[i].y2,&pt[i].z2); } maketable(); double l,r,mid,ans; l = 0.0; r = 40000.0; while(r - l > eps) { mid = (l + r)/ 2; init(); if(twosat(mid)) { ans = mid; l = mid; } else r = mid; } printf("%.3lf\n",ans/2 - 0.0005);//注意处理精度 } return 0;}
- zoj3717 Balloon(二分+2SAT)
- ZOJ 3717 Balloon (2sat+二分)
- zoj 3717 Balloon(二分+2-SAT)
- ZOJ 3717 - Balloon 简单二分+2-sat..精度恶心..
- zoj 3717 - Balloon(2-SAT)
- ZOJ 3717 Balloon(2-sat)
- HDU3622 二分+2-SAT
- HDOJ3622-2SAT,二分
- POJ2749-二分,2SAT
- poj2296(二分+2sat)
- HDU3622(二分+2-SAT)
- HDU3715(二分+2-SAT)
- hdu3622 二分+2sat
- hdu3715 2-sat+二分
- POJ2296二分2sat
- hdu3622 2-SAT+二分
- 2-sat + 二分 hdu3715
- poj 2723【2-SAT+二分】
- jar打包出现java.io.IOException: invalid header field 解决方案
- java代码验证各地区身份证规则
- 密码保存至后台表加密所需的MD5哈希值转换文件CommonHelper.Md5Encrypt
- 离线安装eclipse的svn插件
- cocos2d-x 利用CCArmature 实现换装
- zoj3717 Balloon(二分+2SAT)
- Android 判断网络是否可以访问Internet
- 黑马程序员__装饰设计模式
- Redhat Linux安装JDK 1.7
- 130722CF282解题报告
- AlertDialog 与 PopupWindow的 区别
- IIS下PHP的ISAPI和FastCGI比较
- PHP mysql 事务处理实例
- 在线文档查看方案- 易度云查看