Bomb Game
Time Limit: 10000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 5369 Accepted Submission(s): 1912
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.
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 x
1i, y
1i, x
2i, y
2i, indicating that the coordinates of the two candidate places of the i-th round are (x
1i, y
1i) and (x
2i, y
2i). 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
Recommend
题解:2-SAT
二分答案,二分最终方案中最近两点的距离(因为这个距离的1/2就是圆的半径)
关键是如何进行check
如果两个点a,b之间的距离小于mid,那么这两个点一定不能同时入选。
也就是选择了a必然要选择b',选择了b必然要选择a'。所以a->b',b->a'
然后用tarjan进行缩点,如果a,a'在同一个强连通分量中则说明mid不可行。
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#define N 1003
#define eps 1e-4
using namespace std;
int n,m,top,tot,sz,cnt,belong[N];
int point[N],v[N*N],nxt[N*N],num[N][3],dfsn[N],low[N],st[N],ins[N];
double a[N][3],b[N][3];
void add(int x,int y)
{
tot++; nxt[tot]=point[x]; point[x]=tot; v[tot]=y;
//cout<<x<<" "<<y<<endl;
}
void tarjan(int x)
{
dfsn[x]=low[x]=++sz; st[++top]=x;
ins[x]=1;
for (int i=point[x];i;i=nxt[i]) {
int j=v[i];
if (!dfsn[j]) tarjan(j),low[x]=min(low[x],low[j]);
else if (ins[j]) low[x]=min(low[x],dfsn[j]);
}
if (low[x]==dfsn[x]) {
int j; ++cnt;
do{
j=st[top--];
belong[j]=cnt;
ins[j]=0;
}while (j!=x);
}
}
double pow(double x){
return x*x;
}
double getdis(double x,double y,double px,double py){
return sqrt(pow(x-px)+pow(y-py));
}
bool check(double mid)
{
//cout<<mid<<endl;
tot=0; sz=0; cnt=0; top=0;
memset(point,0,sizeof(point));
for (int i=1;i<n;i++)
for (int l=0;l<=1;l++) {
double x=a[i][l],y=b[i][l];
for (int j=i+1;j<=n;j++)
for (int k=0;k<=1;k++){
double px=a[j][k],py=b[j][k];
if (getdis(x,y,px,py)<mid)
add(num[i][l],num[j][k^1]),add(num[j][k],num[i][l^1]);
}
}
memset(dfsn,0,sizeof(dfsn));
memset(ins,0,sizeof(ins));
memset(belong,0,sizeof(belong));
for (int i=1;i<=n+n;i++)
if (!dfsn[i]) tarjan(i);
for (int i=1;i<=n;i++)
if (belong[i]==belong[i+n]) return false;
return true;
}
int main()
{
// freopen("bomb.in","r",stdin);
// freopen("bomb.out","w",stdout);
while (scanf("%d",&n)!=EOF){
for (int i=1;i<=n;i++)
scanf("%lf%lf%lf%lf",&a[i][0],&b[i][0],&a[i][1],&b[i][1]);
for (int i=1;i<=n;i++) num[i][0]=i,num[i][1]=i+n;
double l=0; double r=10000000; double ans=0;
while (r-l>=eps) {
double mid=(l+r)/2;
if (check(mid)) ans=max(ans,mid),l=mid+eps;
else r=mid-eps;
}
printf("%.2lf\n",ans/2.0);
}
}