hdu 3622 Bomb Game(二分+2-sat判定)

来源:互联网 发布:js时间戳转换 编辑:程序博客网 时间:2024/06/06 02:28

Bomb Game

Time Limit: 10000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 2281    Accepted Submission(s): 766


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
21 1 1 -1-1 -1 -1 121 1 -1 -11 -1 -1 1
 

Sample Output
1.411.00
 

Source
2010 Asia Regional Tianjin Site —— Online Contest
 

Recommend
lcy
 
题目:http://acm.hdu.edu.cn/showproblem.php?pid=3622
题意:给你n对点,每对中选出一个点,画一个圆,所有圆不能相交,使得最小的圆的半径最大
分析:这题要不是知道是2-sat确实无从下手,知道后就简单了,二分答案,那么就知道哪些点不能同时选了,也就是典型的2-sat判定问题,写个二分+强连通搞定
把计算点的距离放到外面初始化,快n倍啊,从2000++ms降到300++ms
PS:2-sat居然跟几何扯上关系了= =,一开始强连通变量搞错wa了,后来低估了答案的大小,又wa了好几次T_T
代码:
#include<cmath>#include<cstdio>#include<iostream>using namespace std;typedef double diy;const int mm=99999;const int mn=222;struct point{    diy x,y;}g[mm];int ver[mm],next[mm];int head[mn],dfn[mn],low[mn],q[mn],id[mn];int i,j,k,n,idx,top,cnt,edge;void add(int u,int v){    ver[edge]=v,next[edge]=head[u],head[u]=edge++;}void dfs(int u){    dfn[u]=low[u]=++idx;    q[top++]=u;    for(int i=head[u],v;i>=0;i=next[i])        if(!dfn[v=ver[i]])            dfs(v),low[u]=min(low[u],low[v]);        else if(!id[v])low[u]=min(low[u],dfn[v]);    if(dfn[u]==low[u])    {        id[u]=++cnt;        while(q[--top]!=u)id[q[top]]=cnt;    }}void Tarjan(){    for(idx=top=cnt=i=0;i<n+n;++i)dfn[i]=id[i]=0;    for(i=0;i<n+n;++i)        if(!dfn[i])dfs(i);}diy d[mn][mn],l,r,m;diy Dis(point p,point q){    return sqrt((p.x-q.x)*(p.x-q.x)+(p.y-q.y)*(p.y-q.y));}bool ok(){    for(edge=i=0;i<n+n;++i)head[i]=-1;    for(i=0;i<n+n;++i)        for(j=i+1;j<n+n;++j)            if((i%n)!=(j%n)&&d[i][j]<2*m)                add(i,(j+n)%(2*n)),add(j,(i+n)%(2*n));    Tarjan();    for(i=0;i<n;++i)        if(id[i]==id[i+n])return 0;    return 1;}int main(){    while(~scanf("%d",&n))    {        for(i=0;i<n;++i)            scanf("%lf%lf%lf%lf",&g[i].x,&g[i].y,&g[i+n].x,&g[i+n].y);        for(i=0;i<n+n;++i)            for(j=0;j<n+n;++j)                d[i][j]=Dis(g[i],g[j]);        l=0,r=1e5;        while(r-l>1e-4)        {            m=(l+r)/2;            if(ok())l=m;            else r=m;        }        printf("%.2lf\n",m);    }    return 0;}


原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 种子发芽后倒了怎么办 3d模型加载错误,怎么办 橡皮树长得太高怎么办 金钻的叶子下垂怎么办 水养竹子烂根怎么办 散尾竹叶尖干枯怎么办 眼睛看不清东西视线模糊怎么办 棒球服领子松垮怎么办 裱水彩纸崩了怎么办 裱水彩纸皱起来怎么办 冬天皮肤的皴了怎么办 六个月宝宝皴脸怎么办 婴儿冬天脸裂了怎么办 手裂了怎么办 小妙招 幼儿园孩子不爱写作业怎么办 2岁宝淘气不听话怎么办 2岁宝宝太调皮怎么办 ae视频加载的慢怎么办 我想你了怎么办表情包 腰闪了不能弯腰怎么办 13岁驼背怎么办才能好 脸僵硬笑不出来怎么办 素描排线太乱了怎么办 4岁小儿不爱吃饭怎么办 僵尸农场下架了怎么办 乐视倒闭了手机怎么办 小孩笑起来嘴歪怎么办 小孩嘴歪了怎么办啊 头发长洗头掉发怎么办 头痒又掉头发怎么办 头皮痒而且掉发怎么办 掉一片头发头痒怎么办 头头发掉的厉害怎么办 掉发严重怎么办吃什么 18岁脱发严重该怎么办 高三学生掉头发怎么办 20岁一直掉头发怎么办 孩子掉头发很厉害怎么办 6岁掉头发正常怎么办 掉头发严重怎么办知乎 20岁有白头发怎么办