您的位置:首页 > 其它

HDU-3622 Bomb Game

2017-07-27 22:26 330 查看


Bomb Game

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

Total Submission(s): 5595    Accepted Submission(s): 2004


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判断可行性。

#include <cstdio>
#include <algorithm>
#include <cstring>
#include <vector>
#include <stack>
#include <cmath>
using namespace std;
const int MAXN = 200+7;
const double eps = 1e-5;
int n;

vector<int>head[MAXN];
int dfn[MAXN],sccno[MAXN],dfs_clock,scc_cnt;
stack<int>S;
int dfs(int u)
{
int lowu=dfn[u]=++dfs_clock;
S.push(u);
for(int i=0,l=head[u].size(); i<l; ++i)
{
int v=head[u][i];
if(!dfn[v])
{
int lowv=dfs(v);
lowu=min(lowu,lowv);
}
else if(!sccno[v])
{
lowu=min(lowu,dfn[v]);
}
}
if(lowu==dfn[u])
{
scc_cnt++;
while(1)
{
int x=S.top();
S.pop();
sccno[x]=scc_cnt;
if(x==u)break;
}
}
return lowu;
}
void find_scc()
{
dfs_clock=scc_cnt=0;
fill(dfn,dfn+n,0);
fill(sccno,sccno+n,0);
for(int i = 0; i < n; ++i)if(!dfn[i])dfs(i);
}
bool ok()
{
find_scc();
for(int i = 0; i < n; i+=2)if(sccno[i] == sccno[i+1])return 0;;
return 1;
}
struct node
{
int x,y;
}p[MAXN];
int main()
{
double low,high,mid;
while(~scanf("%d",&n))
{
for(int i = 0; i < n; ++i)scanf("%d%d%d%d",&p[2*i].x,&p[2*i].y,&p[i*2+1].x,&p[i*2+1].y);
low = 0;
high = 40000.0;
n*=2;
while(high - low >= eps)
{
mid = (low + high)*0.5;
for(int i = 0; i < n; ++i)head[i].clear();
for(int i = 0; i < n; ++i)
{
int b = (i+2) - i%2;
for(int j = b; j < n; ++j)
{
if(hypot(p[i].x-p[j].x,p[i].y-p[j].y) < 2*mid)
{
head[i].push_back(j^1);
//head[j^1].push_back(i);
head[j].push_back(i^1);
//head[i^1].push_back(j);
}
}
}
if(ok())low = mid;
else high = mid;
}
printf("%.2f\n",low);
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  2-sat 图论