您的位置:首页 > 其它

hdu 3622 Bomb Game(2-sat,二分,4级)

2013-06-04 18:15 435 查看

Bomb Game

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

Total Submission(s): 2696 Accepted Submission(s): 894



[align=left]Problem Description[/align]
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.

[align=left]Input[/align]
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].

[align=left]Output[/align]
Output one float number for each test case, indicating the best possible score. The result should be rounded to two decimal places.

[align=left]Sample Input[/align]

2
1 1 1 -1
-1 -1 -1 1
2
1 1 -1 -1
1 -1 -1 1


[align=left]Sample Output[/align]

1.41
1.00


[align=left]Source[/align]
2010 Asia Regional Tianjin Site —— Online Contest

[align=left]Recommend[/align]
lcy

思路:二分最小距离-2-sat 判断可行性,强连通缩点,判断a,a^1不矛盾就行了。

(a,b)矛盾则(a,b^1),(b,a^1)加边,不可盲目加双向边。

这题坑了我近7个小时,两个问题。

1:加了双向边

2:tarjan()有错 instack忘给退了。

#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
using namespace std;
const int mm=200+9;
const double eps=1e-6;
class node
{
public:
double x,y;
} f[mm];
int n;
double dis[mm][mm];
int head[mm],stack[mm],top,cnt,edge,dex,dfn[mm],low[mm],e_to[mm];
int ver[mm*mm],next[mm*mm];
bool instack[mm];
void data()
{
memset(head,-1,sizeof(head));
memset(dfn,0,sizeof(dfn));
memset(instack,0,sizeof(instack));
dex=top=cnt=edge=0;
}
void add(int u,int v)
{   if(u==v)return;
ver[edge]=v;
next[edge]=head[u];
head[u]=edge++;
// ver[edge]=u;
//next[edge]=head[v];
//head[v]=edge++;
}
double get_dis(node a,node b)
{
return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
}
void tarjan(int u)
{
dfn[u]=low[u]=++dex;
stack[top++]=u;
instack[u]=1;
int v;
for(int i=head[u]; ~i; i=next[i])
{
v=ver[i];
if(!dfn[v])
{
tarjan(v);
low[u]=low[u]<low[v]?low[u]:low[v];
}
else if(instack[v])
{
low[u]=low[u]<dfn[v]?low[u]:dfn[v];
}
}
if(dfn[u]==low[u])
{
++cnt;
do
{
v=stack[--top];
instack[v]=0;
e_to[v]=cnt;
}
while(v^u);
}
}
bool two_sat(double x)
{
for(int i=0; i<n; ++i)
for(int j=i+1; j<n; ++j)
if(j^i&&dis[i][j]<x)
{
add(i,j^1),add(j,i^1);
// add(j^1,i);add(i^1,j);
// printf("dis=%lf  %d -> %d\n",dis[i][j],i,j);
//printf("%d %d\n %d %d\n",i,j^1,j,i^1);
}
for(int i=0; i<n; ++i)
if(!dfn[i])
tarjan(i);

// for(int i=0;i<n;++i)
//  cout<<i<<" "<<e_to[i]<<endl;
for(int i=0; i<n; ++i)
if(e_to[i]==e_to[i^1])return 0;
return 1;
}
int main()
{  ///freopen("data.in","r",stdin);
while(~scanf("%d",&n))
{
for(int i=0; i<n; ++i)
scanf("%lf%lf%lf%lf",&f[i+i].x,&f[i+i].y,&f[i+i+1].x,&f[i+i+1].y);
n+=n;
for(int i=0; i<n; ++i)
for(int j=i+1; j<n; ++j)
dis[i][j]=get_dis(f[i],f[j]);
double l=0.0,r=1e9,mid;

while(r-l>eps)
{
data();
mid=(l+r)/2.0;
//  mid=3.80;
//  puts("......................................................");
// printf("%lf----\n",mid);
if(two_sat(mid*2.0))
{l=mid;}
else {r=mid;}
}
printf("%.2lf\n",(l+r)/2.0);
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: