现在的位置: 首页 > 综合 > 正文

HDOJ/HDU 3622 二分+2-sat 天津网络赛

2018年01月20日 ⁄ 综合 ⁄ 共 3123字 ⁄ 字号 评论关闭

Bomb Game

Time Limit: 10000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1630    Accepted Submission(s): 528

Problem 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
 

Source
The 35th ACM/ICPC Asia Regional Tianjin Site
—— Online Contest

刚开始各种撮啊。。
我的代码:

#include<stdio.h>
#include<algorithm>
#include<string.h>
#include<vector>
#include<stack>
#include<math.h>
#define maxn 205
#define eps 1e-12

using namespace std;

struct point
{
	double x;
	double y;
};

int n,m,Index,cnt;
point pa[maxn],pb[maxn];
double dist[maxn][maxn];
int belong[maxn],dfn[maxn],low[maxn];
int used[maxn],instack[maxn];
stack<int>s;
vector<int>map[maxn];

void init()
{
	int i;
	for(i=0;i<maxn;i++)
		map[i].clear();
	while(!s.empty())
		s.pop();
	memset(used,0,sizeof(used));
	memset(instack,0,sizeof(instack));
	memset(dfn,-1,sizeof(dfn));
	memset(low,0,sizeof(low));
	memset(belong,0,sizeof(belong));
	Index=0,cnt=0;
}

int min(int a,int b)
{
	if(a>b)
		return b;
	else
		return a;
}

double dis(point a,point b)
{
	return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
}

void build_map(double r)
{
	int i,j;
	for(i=1;i<=n;i++)
		for(j=i+1;j<=n;j++)
		{
			if(dis(pa[i],pa[j])<r*2)
			{
				map[i].push_back(j+n);
				map[j].push_back(i+n);
			}
			if(dis(pa[i],pb[j])<r*2)
			{
				map[i].push_back(j);
				map[j+n].push_back(i+n);
			}
			if(dis(pb[i],pa[j])<r*2)
			{
				map[i+n].push_back(j+n);
				map[j].push_back(i);
			}
			if(dis(pb[i],pb[j])<r*2)
			{
				map[i+n].push_back(j);
				map[j+n].push_back(i);
			}
		}
}

void tarjan(int u)
{
	int i,v;
	Index++;
	dfn[u]=Index;
	low[u]=Index;
	used[u]=true;
	instack[u]=true;
	s.push(u);
	for(i=0;i<map[u].size();i++)
	{
		v=map[u][i];
		if(!used[v])
		{
			tarjan(v);
			low[u]=min(low[u],low[v]);
		}
		else if(instack[v])
		{
			low[u]=min(low[u],dfn[v]);
		}
	}
	if(dfn[u]==low[u])
	{
		cnt++;
		do
		{
			v=s.top();
			s.pop();
			belong[v]=cnt;
			instack[v]=false;
		}
		while(u!=v);
	}
}

bool judge(double r)
{
	int i;
	init();
	build_map(r);
	for(i=1;i<=n;i++)
		if(dfn[i]==-1)
			tarjan(i);
	for(i=1;i<=n;i++)
		if(belong[i]==belong[i+n])
			return false;
	return true;
}

int main()
{
	int i,j;
	double left,right,mid;
	while(scanf("%d",&n)!=EOF)
	{
		for(i=1;i<=n;i++)
			scanf("%lf%lf%lf%lf",&pa[i].x,&pa[i].y,&pb[i].x,&pb[i].y);
		left=0,right=20000;
		double ans;
		while(fabs(right-left)>=1e-6)
		{
			mid=(left+right)/2.0;
			if(judge(mid))
			{
				ans=mid;
				left=mid;
			}
			else
			{
				right=mid;
			}
		}
		printf("%.2lf\n",ans);
	}
	return 0;
}
 

抱歉!评论已关闭.