HDU 3622 Bomb Game(2-SAT)
来源:互联网 发布:php post 源代码 编辑:程序博客网 时间:2024/05/16 02:06
#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>#include<vector>#include<cmath>using namespace std;const double eps=1e-5;const int maxn=100+5;struct TwoSAT{ int n; vector<int> G[maxn*2]; bool mark[maxn*2]; int s[maxn*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<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<2*n;i++) G[i].clear(); memset(mark,0,sizeof(mark)); } void add_clause(int x,int xval,int y,int yval){ x=x*2+xval; y=y*2+yval; G[x^1].push_back(y); G[y^1].push_back(x); } bool solve(){ for(int i=0;i<2*n;i+=2){ if(!mark[i]&&!mark[i+1]){ c=0; if(!dfs(i)){ while(c) mark[s[--c]]=false; if(!dfs(i+1)) return false; } } } return true; }};TwoSAT solver;struct point{int x,y;}points[maxn][2];int n;bool test(double diff){ solver.init(n); 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++){ int x1=points[i][a].x,y1=points[i][a].y; int x2=points[j][b].x,y2=points[j][b].y; double r=sqrt(abs(x1-x2)*abs(x1-x2)+abs(y1-y2)*abs(y1-y2))/2; if(r+eps<diff) solver.add_clause(i,a^1,j,b^1); } } } } return solver.solve();}int main(){ while(scanf("%d",&n)!=EOF) { for(int i=0;i<n;i++){ for(int j=0;j<2;j++) scanf("%d%d",&points[i][j].x,&points[i][j].y); } double l=0.0,r=30000.0; while(l+eps<r){ double mid=(l+r)/2; if(test(mid)) l=mid;else r=mid; } printf("%.2f\n",l); } return 0;}
0 0
- HDU 3622 Bomb Game【2-SAT 问题】
- hdu 3622 Bomb Game#2-sat+二分
- HDU 3622 Bomb Game(2-SAT)
- HDU 3622 Bomb Game【2-SAT 问题】
- HDU 3622 Bomb Game 2-sat
- 2-sat->HDU 3622 Bomb Game
- hdu 3622 Bomb Game (二分+2-sat)
- HDU 3622 Bomb Game / 2-SAT
- HDU 3622 Bomb Game(2-SAT+二分)
- 【HDU】3622 Bomb Game 2-sat
- hdu 3622 Bomb Game (2-SAT)
- HDU 3622 Bomb Game(2-sat)
- HDU 3622 Bomb Game (二分+2-SAT)
- HDU 3622 Bomb Game【2-SAT + tarjan】
- HDU 3622 Bomb Game 二分 + 2-sat
- HDU 3622 Bomb Game(2-SAT)
- hdu 3622 Bomb Game (2-SAT)
- hdu 3622 Bomb Game(二分+2-sat)
- 精心整理python自动化测试小技巧二
- mybatis中常用的标签
- python读取文件并上传数据库
- 洛谷 P1629 邮递员送信
- log4j配置
- HDU 3622 Bomb Game(2-SAT)
- python生成VOC2007的xml代码
- Duplicate files copied in APK META-INF/notice.txt错误的解决办法
- MyBatis Like模糊查询参考解决策略
- std::ostringstream用法
- linux ffmpeg开发环境搭建(基于ubuntu14.04和ffmpeg3.2)
- SQL中变量用String.Format
- [生存志] 第35节 后羿弯弓射九日
- 【职坐标】高级特性之内部类简介