博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
HDU 3622 Bomb Game 二分+2-SAT
阅读量:4556 次
发布时间:2019-06-08

本文共 2382 字,大约阅读时间需要 7 分钟。

二分爆炸半径R,判断是否可行,如果可行,半径可以继续增加。

之前建图有误,结果一直不对。

 

#include 
#include
#include
#include
#include
#include
using namespace std;const int MAXN = 222;const double eps = 1e-5;struct Point{ double x, y; Point( double x = 0.0, double y = 0.0 ): x(x), y(y) { } void readPoint() { scanf( "%lf%lf", &x, &y ); return; }};struct TwoSAT{ int n; vector
G[ MAXN << 1 ]; bool mark[MAXN << 1]; int S[MAXN << 1], top; bool DFS( int x ) { if ( mark[x^1] ) return false; if ( mark[x] ) return true; mark[x] = true; S[ ++top ] = x; int sz = G[x].size(); for ( int i = 0; i < sz; ++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, false, sizeof(mark) ); return; } 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); return; } bool solved() { for ( int i = 0; i < ( n * 2 ); i += 2 ) if ( !mark[i] && !mark[i + 1] ) { top = 0; if( !DFS(i) ) { while ( top > 0 ) mark[ S[top--] ] = false; if ( !DFS(i + 1) ) return false; } } return true; }};int N;Point P[MAXN][2];TwoSAT Graph;double dist[110][2][110][2];double dcmp( double a ){ if ( fabs(a) < eps ) return 0; return a < 0 ? -1 : 1;}double dis( Point a, Point b ){ return sqrt( (a.x - b.x)*(a.x - b.x) + (a.y - b.y)*(a.y - b.y) );}bool check( double mid ){ Graph.init( N ); mid *= 2.0; 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 ( dcmp( dist[i][a][j][b] - mid ) < 0 ) { Graph.add_clause( i, a ^ 1, j, b ^ 1 ); } } return Graph.solved();}int main(){ while ( scanf( "%d", &N ) == 1 ) { for ( int i = 0; i < N; ++i ) { P[i][0].readPoint(); P[i][1].readPoint(); } 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 ) dist[i][a][j][b] = dist[j][b][i][a] = dis( P[i][a], P[j][b] ); double l = 0.0, r = dis( Point( -10000.0, -10000.0 ), Point( 10000.0, 10000.0 ) ); double mid, ans; while ( r - l > eps ) { mid = ( l + r ) / 2.0; if ( check(mid) ) { ans = mid; l = mid; //printf( "mid = %.2f\n", mid ); } else r = mid; } printf( "%.2f\n", ans ); } return 0;}

 

转载于:https://www.cnblogs.com/GBRgbr/p/3297722.html

你可能感兴趣的文章
关于临界资源访问互斥量的死锁问题
查看>>
django-view层
查看>>
异步加载JS的方法。
查看>>
golang-gorm框架支持mysql json类型
查看>>
【tool】白盒测试
查看>>
图论其一:图的存储
查看>>
20180923-WebService
查看>>
z变换
查看>>
Python - 静态函数(staticmethod), 类函数(classmethod), 成员函数
查看>>
Spring基础2
查看>>
【灵异短篇】这个夜晚有点凉
查看>>
一点小问题
查看>>
pytest 10 skip跳过测试用例
查看>>
MVC身份验证及权限管理
查看>>
It was not possible to find any compatible framework version
查看>>
nodejs概述
查看>>
关于8.0.15版本的mysql下载与安装
查看>>
Redis主从复制看这篇就够了
查看>>
部署和调优 2.3 tomcat中JDK安装
查看>>
洛谷 P1202 [USACO1.1]黑色星期五Friday the Thirteenth 题解
查看>>