zoj 3717 - Balloon(2-SAT)
来源:互联网 发布:外汇软件mt4骗局 编辑:程序博客网 时间:2024/06/13 12:54
裸的2-SAT,详见刘汝佳训练指南P-323
不过此题有个特别需要注意的地方:You should promise that there is still no overlap for any two balloons after rounded.
模版题,
代码如下:
#include <cstdio>#include <cstring>#include <cstdlib>#include <algorithm>#include <string>#include <cmath>#include <queue>#include <stack>#include <vector>#include <map>#define LL long long#define eps 1e-5#define M 205#define mod 1000000007using namespace std;struct Point{ int x, y, z; Point() { } Point(int x, int y, int z) : x(x), y(y), z(z) { } void readPoint() { scanf("%d %d %d", &x, &y, &z); }};struct TwoSAT{ int n; vector<int>G[M*2]; bool mark[M*2]; int S[M*2], c; bool dfs(int x) { if(mark[x^1]) return false; if(mark[x]) return true; mark[x] = true; S[c++] = x; for(int i = 0; i < (int)G[x].size(); ++i) if(!dfs(G[x][i])) return false; return true; } void init(int n) { this->n = n; for(int i = 0; i < n*2; ++i) G[i].clear(); memset(mark, 0, sizeof(mark)); } void add_clause(int x, int y) { G[x^1].push_back(y); G[y^1].push_back(x); } bool solve() { for(int i = 0; i < n*2; i+=2) if(!mark[i] && !mark[i+1]) { c = 0; if(!dfs(i)) { while(c>0) mark[S[--c]] = false; if(!dfs(i+1)) return false; } } return true; }};Point poi[2*M];int dcmp(double a){ if(fabs(a)<eps) return 0; return a<0?-1:1;}double dis(Point a, Point b){ 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));}int ok(int n, double R){ TwoSAT temp; temp.init(n); for(int i = 0; i < 2*n; ++i) for(int j = i+1; j < 2*n; ++j) if(dcmp(dis(poi[i], poi[j])-2*R)<0) { temp.add_clause(i^1, j^1); } return temp.solve();}int main (){ int n; while(~scanf("%d", &n)) { for(int i = 0; i < 2*n; ++i) poi[i].readPoint(); double l = 0.0, r = dis(Point(0,0,0), Point(10000,10000,10000)), mid; while(r-l>eps) { mid = (r+l)/2; if(ok(n, mid)) l = mid; else r = mid; } double ans = (int)(mid*1000+0.5)/1000.0;//注意!!! if(!ok(n, ans)) ans-=0.001; printf("%.3lf\n", ans); } return 0;}
- zoj 3717 - Balloon(2-SAT)
- ZOJ 3717 Balloon (2sat+二分)
- zoj 3717 Balloon(二分+2-SAT)
- ZOJ 3717 Balloon(2-sat)
- ZOJ 3717 - Balloon 简单二分+2-sat..精度恶心..
- zoj 3717 2-SAT
- ZOJ 3717 2-sat
- zoj 3717 2-sat
- zoj3717 Balloon(二分+2SAT)
- ZOJ 3717: Balloon
- ZOJ 3717 Balloon 解题报告
- ZOJ 3717 HDU 3622 二分+2-SAT
- ZOJ 3717 2-sat 进位精度
- ZOJ 3717 二分+2-sat判定。
- ZOJ 3422 2-SAT
- zoj 3717 二分+2sat tarjan求强连通
- [ZOJ] 1003 Crashing Balloon
- zoj 1003 Crashing Balloon
- 读《小菜编程成长记》理解三层架构的一些记录
- android实现两个listview的同步滚动
- C++标准IO-输入状态
- ubuntu中svn客户端使用
- CodeRush教程二 代码风格
- zoj 3717 - Balloon(2-SAT)
- C++标准IO-文件的操作
- Delphi中or的使用
- C++标准IO-字符串操作类
- Spring第二个程序---依赖注入
- (win7)虚拟机和主机通信
- WPF应用程序连接数据库语句。
- z-index在IE中的迷惑
- C++标准IO-综述