一个很玄乎的问题,但听到2-SAT之后就豁然开朗了。题目的意思是这样的,给你n个点群,每个点群里面有两个点,你要在每个点群里面选一个点,以这些点做半径为r的圆,然后r会有一个最大值,问的就是怎么选这些点使得r最大。

2-SAT就是对于每个变量有一些制约的关系   a->b 表示选了a就就要选b。然后我们二分这个半径,对于两点间距离<2*r的点(a,b)选了a就不能选b,选了b就不能选a,以此构图。然后跑一次强连通分量。最后判是否有解的时候就是判对于两个属于相同点群的点,它们不能处于同一强连通分量下。写的时候跪的点实在太多了,数组越界呀,强连通写错呀,精度呀,这样的题太坑爹了- -0

#pragma warning(disable:4996)
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#define ll long long
#define maxn 220
#define eps 1e-8
using namespace std; struct Point
{
double x, y, z;
Point(double xi, double yi, double zi) :x(xi), y(yi), z(zi){}
Point(){}
}p[maxn * 2]; 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));
} double dis[maxn * 2][maxn * 2]; int low[maxn * 2];
int pre[maxn * 2];
int dfs_clock;
int sta[maxn * 2];
int st;
int sccno[maxn * 2];
int n;
vector<int> G[maxn * 2];
int scc_cnt; int dcmp(double x){
return (x > eps) - (x < -eps);
} void dfs(int u){
low[u] = pre[u] = ++dfs_clock;
sta[++st] = u;
for (int i = 0; i < G[u].size(); i++){
int v = G[u][i];
if (!pre[v]){
dfs(v);
low[u] = min(low[u], low[v]);
}
else if (!sccno[v]){
low[u] = min(low[u], pre[v]);
}
}
if (low[u] == pre[u]){
++scc_cnt;
while (1){
int x = sta[st]; st--;
sccno[x] = scc_cnt;
if (x == u) break;
}
}
} bool judge(double x)
{
memset(sccno, 0, sizeof(sccno));
memset(pre, 0, sizeof(pre));
memset(low, 0, sizeof(low));
st = 0; dfs_clock = 0;
scc_cnt = 0;
for (int i = 0; i <= 2 * n; i++) G[i].clear(); for (int i = 0; i < n; i++){
for (int j = i + 1; j < n; j++){
if (dcmp(dis[i][j] - 2 * x) < 0){
G[i].push_back(j + n);
G[j].push_back(i + n);
}
if (dcmp(dis[i][j + n] - 2 * x) < 0){
G[i].push_back(j);
G[j + n].push_back(i + n);
}
if (dcmp(dis[i + n][j] - 2 * x) < 0){
G[i + n].push_back(j + n);
G[j].push_back(i);
}
if (dcmp(dis[i + n][j + n] - 2 * x) < 0){
G[i + n].push_back(j);
G[j + n].push_back(i);
}
}
}
for (int i = 0; i < 2 * n; i++){
if (!pre[i]) dfs(i);
}
for (int i = 0; i < n; i++){
if (sccno[i] == sccno[i + n]) return false;
}
return true;
} int main()
{
while (cin >> n)
{
for (int i = 0; i < n; i++){
scanf("%lf%lf%lf", &p[i].x, &p[i].y, &p[i].z);
scanf("%lf%lf%lf", &p[i + n].x, &p[i + n].y, &p[i + n].z);
}
for (int i = 0; i < 2 * n; i++){
for (int j = i + 1; j < 2 * n; j++){
dis[i][j] = dis[j][i] = dist(p[i], p[j]);
}
}
double l = 0, r = 1e10;
while (dcmp(r - l)>0){
double mid = (l + r) / 2;
if (judge(mid)) l = mid;
else r = mid;
}
int tmp = l * 1000;
double ans = tmp / 1000.0;
printf("%.3lf\n", ans);
}
return 0;
}

ZOJ3717 Balloon(2-SAT)的更多相关文章

  1. 多边形碰撞 -- SAT方法

    检测凸多边形碰撞的一种简单的方法是SAT(Separating Axis Theorem),即分离轴定理. 原理:将多边形投影到一条向量上,看这两个多边形的投影是否重叠.如果不重叠,则认为这两个多边形 ...

  2. HDOJ 1004 Let the Balloon Rise

    Problem Description Contest time again! How excited it is to see balloons floating around. But to te ...

  3. hdu 1004 Let the Balloon Rise

    Let the Balloon Rise Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Oth ...

  4. 【ZOJ1003】Crashing Balloon(DFS)

    Crashing Balloon Time Limit: 2 Seconds      Memory Limit: 65536 KB On every June 1st, the Children's ...

  5. Let the Balloon Rise

    Problem Description Contest time again! How excited it is to see balloons floating around. But to te ...

  6. 杭电1170 Balloon Comes

    Problem Description The contest starts now! How excited it is to see balloons floating around. You, ...

  7. Let the Balloon Rise 分类: HDU 2015-06-19 19:11 7人阅读 评论(0) 收藏

    Let the Balloon Rise Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Oth ...

  8. HDU 1004 Let the Balloon Rise map

    Let the Balloon Rise Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Oth ...

  9. HDU1004 Let the Balloon Rise(map的简单用法)

    Let the Balloon Rise Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others ...

随机推荐

  1. malloc calloc realloc,new区别联系以及什么时候用

    三个函数的申明分别是:void* realloc(void* ptr, unsigned newsize);void* malloc(unsigned size);void* calloc(size_ ...

  2. linux新增一块硬盘加入原有分区

    原有硬盘空间已经不足,添加一块新硬盘,并且加入到原根目录下 查看新硬盘 1 2 fdisk -l Disk /dev/sdb: 240.1 GB, 240057409536 bytes 在新硬盘上创建 ...

  3. [iPhone高级] 基于XMPP的IOS聊天客户端程序(IOS端一)

    介绍完了服务器,这篇我们就要介绍重点了,写我们自己的IOS客户端程序 先看一下我们完成的效果图 首先下载xmppframework这个框架,下载 点ZIP下载 接下来,用Xcode新建一个工程 将以下 ...

  4. 条款3:尽可能地使用const

    如下为const修饰的几种类型: char name[] = "benxintuzi"; char* p1 = name;                // non-const ...

  5. 005--VS C++ 加载位图

    //全局变量 HDC mdc; //--------------------------------------------InitInstance() 函数--------------------- ...

  6. c# 各种排序算法+找第二大的数+句子单词反转

    冒泡排序 // 冒泡排序 bubble sort public static int[] BubbleSort(int []array) { bool isContinue = true; ; i & ...

  7. LC_ALL=C

    设置LC_ALL=C,可以让sort按照字节排序;

  8. action属性

    action属性 2013年7月8日 14:52 Path: action的访问路径,以"/"开头 Type: action的类型 Name: action使用的actionFor ...

  9. self.a 和 _a 的区别

    在OC中我们可以通过指令@property定义属性. OC对属性封装了许多方法,同时也会自动实现一些方法,相比实例变量,感觉更加面向对象些. 一般定义属性的方法如下,在Class Test中定义属性i ...

  10. 莫名戳中"肋骨"的文章

    1 起初,我们总是会害怕,害怕不能得到自己渴望的物质生活,害怕遇不到那个好好爱自己的人,害怕失去青春也换不回事业上的进步,害怕会做下一个让自己悔恨的决定,可这一路,我们就是这样踩着自己的害怕和悔恨走来 ...