2-sat->HDU 3622 Bomb Game

Bomb Game
Time Limit:3000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u

Description

Robbie is playing an interesting computer game. The game field is an unbounded 2-dimensional region. There are N rounds in the game. At each round, the computer will give Robbie two places, and Robbie should choose one of them to put a bomb. The explosion area of the bomb is a circle whose center is just the chosen place. Robbie can control the power of the bomb, that is, he can control the radius of each circle. A strange requirement is that there should be no common area for any two circles. The final score is the minimum radius of all the N circles.
Robbie has cracked the game, and he has known all the candidate places of each round before the game starts. Now he wants to know the maximum score he can get with the optimal strategy.
 

Input

The first line of each test case is an integer N (2 <= N <= 100), indicating the number of rounds. Then N lines follow. The i-th line contains four integers x1i, y1i, x2i, y2i, indicating that the coordinates of the two candidate places of the i-th round are (x1i, y1i) and (x2i, y2i). All the coordinates are in the range [-10000, 10000].
 

Output

Output one float number for each test case, indicating the best possible score. The result should be rounded to two decimal places.
 

Sample Input

     
     
2 1 1 1 -1 -1 -1 -1 1 2 1 1 -1 -1 1 -1 -1 1
 

Sample Output

     
     
1.41 1.00
 

#include <iostream>
#include <cmath>
#include <string.h>
#include <algorithm>
#include <cstdio> 
#include <stack>

using namespace std;

#define MAXN 200 + 10
#define eps 1e-5

int head[MAXN], e, ind, cnt, n;
int dfn[MAXN], low[MAXN];
int belong[MAXN];
bool vis[MAXN];
bool ins[MAXN];

struct Node
{
	int x, y;
}temp[MAXN];

struct Edge
{
	int v, next;
}edge[200 * MAXN];

int mul(int x)
{
	return x * x;
}

double distanceto(Node a, Node b)
{
	return sqrt((double)(mul(a.x - b.x) + mul(a.y - b.y)));	
}

void add(int u, int v)
{
	edge[e].v = v;
	edge[e].next = head[u];
	head[u] = e++;
}

void init()
{
	e = cnt = ind = 0;
	memset(head, -1, sizeof(head));
	memset(dfn, 0, sizeof(dfn));
	memset(ins, false, sizeof(ins));
	memset(vis, false, sizeof(vis));
	memset(belong, 0, sizeof(belong));
}

stack <int> s;

void tarjan(int u)
{
	dfn[u] = low[u] = ++ind;
	
	ins[u] = true;
	
	s.push(u);
	
	for (int i = head[u]; i != -1; i = edge[i].next)
	{
		int v = edge[i].v;
		
		if (!dfn[v])
		{
			tarjan(v);
			
			low[u] = min(low[u], low[v]);
		}
		else if (ins[v])
		{
			low[u] = min(low[u], dfn[v]);
		}
	}
	
	if (low[u] == dfn[u])
	{
		cnt++;
		int x;
		
		do
		{
			x = s.top();
			s.pop();
			ins[x] = false;
			belong[x] = cnt;
		}while (x != u);
	}
}

bool is_true()
{
	for (int i = 0; i < 2 * n; i++)
	{
		if (!dfn[i])
		{
			tarjan(i);
		}
	}
	
	for (int i = 0; i < n; i++)
	{
		if (belong[2 * i] == belong[2 * i + 1])
		{
			return false;
		}
	}
	
	return true;
}

void solve()
{
	int totline = 0;
	
	double ans = 0;
	double low = 0, high = 20000.0 * sqrt(2.0);
	
	while (low <= high)
	{
		ans = (low + high) / 2.0;
		
		init();
	
		for (int i = 0; i < 2 * n - 2; i++)
		{
			for (int j = i + 1 + !(i & 1); j < 2 * n; j++)
			{
				if (distanceto(temp[i], temp[j]) < ans)
				{
					add(i, j ^ 1);
					add(j, i ^ 1);
				}
			}
		}
		
		if (is_true())
		{
			low = ans + eps;
		}
		else
		{
			high = ans - eps;
		}
	}
	
	printf("%.2lf\n", ans / 2.0);
}

void input()
{	
	while (cin >> n)
	{
		int tot = 0;
		
		for (int i =  0; i < n; i++)
		{
			cin >> temp[2 * i].x >> temp[2 * i].y;
			cin >> temp[2 * i + 1].x >> temp[2 * i + 1].y;
		}
		
		solve();
	}
}

int main()
{
	std::ios::sync_with_stdio(false);
	input();
	return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值