您的位置:首页 > 其它

Hdu 3622 Bomb Game 2-SAT+二分

2017-09-15 22:16 399 查看


Bomb Game

Time Limit: 10000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)

Total Submission(s): 5672    Accepted Submission(s): 2048


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

2-SAT入门。

给你一些点对,要求从每对点当中选一个作圆,使得最后所有圆不相交。问所有圆的最小半径的最大值是多少。

二分圆的半径r,构图进行2-SAT。若两个点a,b的距离大于r,则说明它们不能被同时选择,连边a,b'、b,a'。

接下来就是根据2-SAT的判定规则进行判定,判定是否有一种选择方案满足所构建的图。

#include <cstdio>
#include <iostream>
#include <string.h>
#include <string>
#include <map>
#include <queue>
#include <vector>
#include <set>
#include <algorithm>
#include <math.h>
#include <cmath>
#include <stack>
#define mem0(a) memset(a,0,sizeof(a))
#define meminf(a) memset(a,0x3f,sizeof(a))
using namespace std;
typedef long long ll;
typedef double db;
const int maxn=205,maxk=200005,inf=0x3f3f3f3f;
const ll llinf=0x3f3f3f3f3f3f3f3f;
const db pi=acos(-1.0),eps=1e-4;
int x[maxn],y[maxn],head[maxn],color[maxn],dfn[maxn];
int num,cnt;

struct Edge {
int from,to,pre;
};
Edge edge[maxk*2];

void addedge(int from,int to) {
edge[num]=(Edge){from,to,head[from]};
head[from]=num++;
}

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

db dis(int i,int j) {
return sqrt(sqr(x[i]-x[j])+sqr(y[i]-y[j]));
}

void buildmap(int n,db mid) {
int i,j;
num=0;memset(head,-1,sizeof(head));
for (i=0;i<n*2;i++)
for (j=i+1;j<n*2;j++) {
if (i/2==j/2) continue;
if (dis(i,j)<=mid)
addedge(i,j^1),addedge(j,i^1);
}
/* cout << mid << endl;
for (i=0;i<num;i++) {
cout << edge[i].from << ' ' << edge[i].to << endl;
}
cout << '\n';*/
}

bool dfs(int now) {
if (color[now]==1) return true;
if (color[now]==2) return false;
color[now]=1;color[now^1]=2;
dfn[++cnt]=now;
for (int i=head[now];i!=-1;i=edge[i].pre) {
int to=edge[i].to;
if (!dfs(to)) return false;
}
return true;
}

bool check(int n) {
mem0(color);
int i,j;
for (i=0;i<n;i++) {
if (!color[i*2]) {
cnt=0;
if (!dfs(i*2)) {
for (j=1;j<=cnt;j++) color[dfn[j]]=color[dfn[j]^1]=0;
if (!dfs(i*2+1)) return false;
}
}
}
return true;
}

int main() {
int n;
while (scanf("%d",&n)!=EOF) {
int i;
for (i=0;i<2*n;i++)
scanf("%d%d",&x[i],&y[i]);
db l=1e-2,r=40000.0,ans=0.0,mid;
while (fabs(r-l)>eps) {
mid=(l+r)/2.0;
buildmap(n,mid);
if (check(n)) ans=mid,l=mid; else r=mid;
}
ans/=2.0;
printf("%.2lf\n",ans);
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: