[BZOJbegin][NOIP十连测热身赛b]escape(二分+bfs)
来源:互联网 发布:北大青鸟网络培训课程 编辑:程序博客网 时间:2024/06/11 04:14
题目描述
传送门
题解
预处理每一个点到离它最近的敌人的距离。
二分答案,判定的时候也用bfs,只有不在距离范围内的点才能走。
代码
#include<iostream>#include<cstring>#include<cstdio>#include<queue>using namespace std;#define N 1005int sx[4]={0,0,1,-1}; int sy[4]={1,-1,0,0};int n,x,y,x1,y1,x2,y2,inf,ans,sum,cnt;struct hp{int x,y;}pt[N*10];int dis[N][N],step[N][N];queue <hp> q;bool check(int mid){ if (dis[x1][y1]<mid) return false; while (!q.empty()) q.pop(); q.push((hp){x1,y1}); memset(step,127,sizeof(step)); step[x1][y1]=0; while (!q.empty()) { hp now=q.front(); q.pop(); for (int i=0;i<4;++i) { int u=now.x+sx[i],v=now.y+sy[i]; if (u<0||v<0||u>x||v>y||dis[u][v]<mid||step[u][v]!=inf) continue; step[u][v]=step[now.x][now.y]+1; if (u==x2&&v==y2) { cnt=step[u][v]; return true; } q.push((hp){u,v}); } } return false;}void find(){ int l=0,r=2000,mid; while (l<=r) { mid=(l+r)>>1; if (check(mid)) ans=mid,sum=cnt,l=mid+1; else r=mid-1; }}int main(){ scanf("%d%d%d",&n,&x,&y); x--; y--; scanf("%d%d%d%d",&x1,&y1,&x2,&y2); memset(dis,127,sizeof(dis));inf=dis[0][0]; for (int i=1;i<=n;++i) { scanf("%d%d",&pt[i].x,&pt[i].y); q.push((hp){pt[i].x,pt[i].y}); dis[pt[i].x][pt[i].y]=0; } while (!q.empty()) { hp now=q.front(); q.pop(); for (int i=0;i<4;++i) { int u=now.x+sx[i],v=now.y+sy[i]; if (u<0||v<0||u>x||v>y||dis[u][v]!=inf) continue; dis[u][v]=dis[now.x][now.y]+1; q.push((hp){u,v}); } } find(); printf("%d %d\n",ans,sum);}
0 0
- [BZOJbegin][NOIP十连测热身赛b]escape(二分+bfs)
- Escape from Enemy Territory(二分+bfs)
- [BZOJbegin][NOIP十连测第九场]小P的单调数列(数学相关+dp+bit)
- HDU 2337 Escape from Enemy Territory(BFS+二分优化)
- hdu 2337 Escape from Enemy Territory (presolve bfs +bfs+二分)
- [BZOJbegin][noip2016十连测第八场]神炎皇(数学相关:gcd)
- [BZOJbegin][noip2016十连测第八场]降雷皇(dp+线段树)
- [BZOJbegin][noip2016十连测第八场]幻魔皇(dp)
- FZU escape(两个bfs)
- HDU 3533 Escape(BFS)
- 【HDU 3533】Escape(BFS)
- HDU3533:Escape(BFS) (D)
- POJ 3601 Escape from Enemy Territory (二分+BFS+预处理)
- poj 3501 Escape from Enemy Territory 二分+bfs
- hdu 2337 Escape from Enemy Territory (二分枚举+预处理+bfs)
- hdu2337 Escape From Enemy Territory---二分bfs+预处理
- poj 3501 Escape from Enemy Territory(预处理&二分&bfs)
- “玲珑杯”ACM 热身赛 # 2.5 B -- B-E (dp)
- 数据库中聚簇索引与非聚簇索引的区别
- 网站开发设置创建的JSP文件默认的代码
- 【模板】基础算法&&小算法
- 数组中有一个数字出现的次数超过数组长度的一半,请找出这个数字
- makefile
- [BZOJbegin][NOIP十连测热身赛b]escape(二分+bfs)
- Java堆、栈、常量池和String的详细讲解
- [问题解决] maven: Could not calculate build plan: xxx
- 几种使用了CNN(卷积神经网络)的文本分类模型
- xilinx生成mcs,下载flash问题解决方法
- 字体缩写
- 欢迎使用CSDN-markdown编辑器
- 数据挖掘--Apriori导论
- Oracle 左连接、右连接、全外连接、(+)号作用