Bomb Game

hdu3622:http://acm.hdu.edu.cn/showproblem.php?pid=3622

题意:你有n次,每次你可以在平面上放置一个点,并且每一次都会有两个位置可以选,每一次只能选择其中一个。然后在自己位置上以该点为圆心画圆,这n个圆不能相交,问你最后最小的圆的半径的最大值是多少。

题解:二分+2-sat。对于2-sat的建图始终很迷糊。这里的一次有两个点,并且每一次能选择其中一个,这就相当于把n个点弄成了2*n点。如果i--j距离太近 ,则建边i-->~j,j—>~i.

  1 #include<cstdio>
  2 #include<cstring>
  3 #include<algorithm>
  4 #include<iostream>
  5 #include<cmath>
  6 using namespace std;
  7 const int N=310;
  8 const int M=30010;
  9 const double eps=1e-4;
 10 struct Edge{
 11     int to,next;
 12 } edge[M];
 13 struct Node{
 14   double x;
 15   double y;
 16 }num1[600];
 17 int  n,m,cnt,dep,top,atype;
 18 int  dfn[N],low[N],vis[N],head[N],st[N],belong[N],in[N],out[N],sum[N];
 19 //sum[i]记录第i个连通图的点的个数,in[i],out[i],表示缩点之后点的入度和初度。
 20 void init(){
 21       cnt=dep=top=atype=0;
 22     memset(head,-1,sizeof(head));
 23     memset(dfn,0,sizeof(dfn));
 24     memset(low,0,sizeof(low));
 25     memset(vis,0,sizeof(vis));
 26     memset(belong,0,sizeof(belong));
 27     memset(in,0,sizeof(in));
 28     memset(out,0,sizeof(out));
 29     memset(sum,0,sizeof(sum));
 30 }
 31 void addedge(int u,int v){
 32     edge[cnt].to=v;
 33     edge[cnt].next=head[u];
 34     head[u]=cnt++;
 35 }
 36
 37 void Tarjan(int u){
 38     dfn[u]=low[u]=++dep;
 39     st[top++]=u;
 40     vis[u]=1;
 41     for(int i=head[u]; i!=-1; i=edge[i].next){
 42         int v=edge[i].to;
 43         if(!dfn[v]){
 44             Tarjan(v);
 45             low[u]=min(low[u],low[v]);
 46         }
 47         else if(vis[v]){
 48             low[u]=min(low[u],dfn[v]);
 49         }
 50     }
 51     int j;
 52     if(dfn[u]==low[u]){
 53         atype++;
 54         do{
 55             j=st[--top];
 56             belong[j]=atype;
 57             sum[atype]++;   //记录每个连通分量中点的个数
 58             vis[j]=0;
 59         }
 60         while(u!=j);
 61     }
 62 }
 63 bool judge(double mid){
 64     init();
 65     //int base=2*n;
 66     for(int i=1;i<=2*n;i++){
 67         for(int j=i+1;j<=2*n;j++){
 68             double dis=sqrt((num1[i].x-num1[j].x)*(num1[i].x-num1[j].x)+(num1[i].y-num1[j].y)*(num1[i].y-num1[j].y));
 69             if(dis<2*mid){
 70                 if(i<=n&&j<=n){
 71                     addedge(i,j+n);
 72                     addedge(j,i+n);
 73                 }
 74                 if(i<=n&&j>n){
 75                     addedge(i,j-n);
 76                     addedge(j,i+n);
 77                 }
 78                 if(i>n&&j<=n){
 79                     addedge(i,j+n);
 80                     addedge(j,i-n);
 81                 }
 82                 if(i>n&&j>n){
 83                     addedge(i,j-n);
 84                     addedge(j,i-n);
 85                 }
 86
 87             }
 88         }
 89     }
 90     for(int i=1;i<=2*n;i++)
 91       if(!dfn[i])Tarjan(i);
 92     for(int i=1;i<=n;i++)
 93        if(belong[i]==belong[i+n])
 94           return false;
 95
 96   return true;
 97
 98 }
 99 int main(){
100     while(~scanf("%d",&n)){
101         for(int i=1;i<=n;i++){
102         scanf("%lf %lf %lf %lf",&num1[i].x,&num1[i].y,&num1[i+n].x,&num1[i+n].y);
103         }
104         double l=0,r=10000,ans=0;
105         while(abs(l-r)>eps){
106             double mid=(l+r)/2.0;
107             if(judge(mid)){
108                 ans=mid;
109                 l=mid;
110             }
111             else{
112                 r=mid;
113             }
114         }
115         printf("%.2f\n",ans);
116     }
117
118 }

时间: 2024-07-30 10:21:14

Bomb Game的相关文章

CSAPP 3e: Bomb lab (secret_phase)

这是秘密关卡,需要通过主动调用secret_phase函数才能触发,可以通过call secret 或者jump *0x地址来调用. 贴出函数:(fun7函数部分没有注释,后边续上了手写的图来解析这个函数了) 0000000000401204 <fun7>: 401204: 48 83 ec 08 sub $0x8,%rsp 401208: 48 85 ff test %rdi,%rdi 40120b: 74 2b je 401238 <fun7+0x34>;如果%rdi==0,r

CSAPP 3e: Bomb lab (phase_6)

这一关很复杂,需要非常耐心.如果感觉容易在循环中绕晕,可以参考一下我最后附上的画图分析法2333,小把戏,不过挺有用的. 先看函数phase_6: 00000000004010f4 <phase_6>: 4010f4: 41 56 push %r14 4010f6: 41 55 push %r13 4010f8: 41 54 push %r12 4010fa: 55 push %rbp 4010fb: 53 push %rbx 4010fc: 48 83 ec 50 sub $0x50,%rs

CSAPP 3e: Bomb lab (phase_5)

调出phase_5函数: 0000000000401062 <phase_5>: 401062: 53 push %rbx 401063: 48 83 ec 20 sub $0x20,%rsp 401067: 48 89 fb mov %rdi,%rbx 40106a: 64 48 8b 04 25 28 00 mov %fs:0x28,%rax ;此处搞不懂 401071: 00 00 401073: 48 89 44 24 18 mov %rax,0x18(%rsp) 401078: 31

HDU 3622 Bomb Game(二分+2-SAT)

Bomb Game Time Limit: 10000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 5396    Accepted Submission(s): 1925 Problem Description Robbie is playing an interesting computer game. The game field is an unbounde

[HDU3555]Bomb

试题描述 The counter-terrorists found a time bomb in the dust. But this time the terrorists improve on the time bomb. The number sequence of the time bomb counts from 1 to N. If the current number sequence includes the sub-sequence "49", the power o

HDU 3555 —— Bomb

Bomb Problem Description The counter-terrorists found a time bomb in the dust. But this time the terrorists improve on the time bomb. The number sequence of the time bomb counts from 1 to N. If the current number sequence includes the sub-sequence "4

HDU 5653 Bomber Man wants to bomb an Array. DP

Bomber Man wants to bomb an Array. Problem Description Given an array and some positions where to plant the bombs, You have to print the Total Maximum Impact. Each Bomb has some left destruction capability L and some right destruction capability R wh

Bomb

Description The counter-terrorists found a time bomb in the dust. But this time the terrorists improve on the time bomb. The number sequence of the time bomb counts from 1 to N. If the current number sequence includes the sub-sequence "49", the

hdu 3555 Bomb(数位dp)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3555 题目大意:就是给你一个数n,判断从0到n有多少个数含有数字49...... 是不是觉得跟hdu2089很相似呀... 思路:跟hdu2089一样的,注意给出的数比较大,所以这儿用__int64  .... code: #include<cstdio> #include<iostream> #include<cstring> #include<algorithm&

HDOJ 3622 Bomb Game 2-sat

http://acm.hdu.edu.cn/showproblem.php?pid=3622 题意:上个月写的,题目好像是说一对点要选一个引爆,引爆半径自己选,任意两圆不能相交,最后分数是所有圆的最小半径,求最大分数. 分析:二分半径,2-sat判定可行性. 1 #include<cstdio> 2 #include<algorithm> 3 #include<cstring> 4 #include<cmath> 5 using namespace std;