Bomb Game
Time Limit: 10000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 3703 Accepted Submission(s): 1279
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
2010 Asia Regional Tianjin Site —— Online Contest
题意:有n对炸弹,你只能从每对里选出一个每一个都有个坐标,要求求出这些炸弹的爆炸范围的最大值(爆炸范围不能和其他炸弹相交)。
每对中只能选一个,很容易想到2-SAT,然后求出最大,又想到了二分。。这题就是二分加2-SAT。
枚举两个点之间的距离(除以2就是答案),如果两个炸弹之间的距离比这个还小说明这两个不能同时爆炸(就是这两个中只能选一个),我把每对炸弹分成了左边一个右边一个,i<<1表示选第i对中左边的,i<<1|1表示选第i对中右边的,然后按上面的思想枚举点建图,然后tarjan判下符不符合就可以了。
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<stack>
#include<cmath>
using namespace std;
const int MAXN=210;
const int MAXE=40010;
int head[MAXN],size;
struct EDGE
{
int v,next;
}edge[MAXE];
int sccno[MAXN],pre[MAXN],low[MAXN],dfs_clock,sc_cnt;
stack<int> S;
void init()
{
memset(sccno,0,sizeof(sccno));
memset(pre,0,sizeof(pre));
memset(head,-1,sizeof(head));
dfs_clock=sc_cnt=size=0;
}
void add_edge(int u,int v)
{
edge[size].v=v;
edge[size].next=head[u];
head[u]=size++;
}
void tarjan(int u)
{
pre[u]=low[u]=++dfs_clock;
S.push(u);
for(int i=head[u];i!=-1;i=edge[i].next)
{
int v=edge[i].v;
if(!pre[v])
{
tarjan(v);
low[u]=min(low[u],low[v]);
}
else if(!sccno[v])
{
low[u]=min(low[u],pre[v]);
}
}
if(low[u]==pre[u])
{
sc_cnt++;
while(1)
{
int x=S.top();
S.pop();
sccno[x]=sc_cnt;
if(u==x)
break;
}
}
}
double dist(int x1,int y1,int x2,int y2)
{
return (double)((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
}
int lx[110],ly[110],rx[110],ry[110],n;
void build(double mid)
{
init();
for(int i=0;i<n;i++)
{
for(int j=0;j<n;j++)
{
if(i==j)
continue;
if(dist(lx[i],ly[i],lx[j],ly[j])<mid)
{
add_edge(i<<1,j<<1|1);
add_edge(j<<1,i<<1|1);
}
if(dist(rx[i],ry[i],rx[j],ry[j])<mid)
{
add_edge(i<<1|1,j<<1);
add_edge(j<<1|1,i<<1);
}
if(dist(lx[i],ly[i],rx[j],ry[j])<mid)
{
add_edge(i<<1,j<<1);
add_edge(j<<1|1,i<<1|1);
}
if(dist(rx[i],ry[i],lx[j],ly[j])<mid)
{
add_edge(i<<1|1,j<<1|1);
add_edge(j<<1,i<<1);
}
}
}
}
bool test()
{
for(int i=0;i<2*n;i++)
if(!pre[i])
tarjan(i);
for(int i=0;i<n;i++)
{
if(sccno[i<<1]==sccno[i<<1|1])
return 0;
}
return 1;
}
int main()
{
int i;
while(scanf("%d",&n)!=EOF)
{
for(i=0;i<n;i++)
{
scanf("%d%d%d%d",&lx[i],&ly[i],&rx[i],&ry[i]);
}
double l=0,r=10000;
double ans=0;
while(r-l>=1e-4)
{
double mid=(l+r)/2;
build(mid*mid);
if(test())
{
ans=mid;
l=mid;
}
else
r=mid;
}
printf("%.2f\n",ans/2);
}
return 0;
}

本文介绍了一种结合二分查找与2-SAT算法解决特定炸弹放置游戏的最优策略问题。游戏中玩家需选择每轮出现的两个点之一放置炸弹,并确保各炸弹爆炸范围不重叠,以最大化最小爆炸半径。
462

被折叠的 条评论
为什么被折叠?



