(2016弱小联盟十一专场10.3) Help the Princess! BFS
来源:互联网 发布:网络划分的策略 编辑:程序博客网 时间:2024/06/09 21:43
题目连接:
https://acm.bnu.edu.cn/v3/statments/jag2016.pdf
分析:
直接判断‘%’到‘@’和最近的‘$’的距离,如果 ‘%’到‘@’小于%’到最近的‘$’的距离则输出YES否则输出NO
AC代码:
#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>#include <queue>#include <cmath>using namespace std;const int maxn = 210;char mmap[maxn][maxn];int h,w;int ansp,anss;int dir[2][4] = {0,0,1,-1,1,-1,0,0};bool vis[maxn][maxn];struct node{ int x,y,step;};void bfs(int x,int y){ memset(vis,false,sizeof(vis)); queue<node> q; node now,ne; now.x = x; now.y = y; now.step = 0; q.push(now); vis[x][y] = true; while(!q.empty()) { now = q.front(); q.pop(); for(int i=0;i<4;i++) { ne.x = now.x + dir[0][i]; ne.y = now.y + dir[1][i]; if(!vis[ne.x][ne.y] && ne.x >= 1 && ne.x <= h && ne.y >= 1 && ne.y <= w && mmap[ne.x][ne.y]!='#') { ne.step = now.step + 1; vis[ne.x][ne.y] = true; if(mmap[ne.x][ne.y] == '@') ansp = min(ne.step,ansp); else if(mmap[ne.x][ne.y] == '$') anss = min(ne.step,anss); q.push(ne); } } if(ansp < 9999999 && anss < 9999999) break; }}int main(){ while(scanf("%d%d",&h,&w)!=EOF) { int x,y; ansp = anss = 9999999; getchar(); for(int i=1;i<=h;i++) { for(int j=1;j<=w;j++) { scanf("%c",&mmap[i][j]); if(mmap[i][j] == '%') { x = i; y = j; } } getchar(); } bfs(x,y); if(ansp < anss) printf("Yes\n"); else printf("No\n"); } return 0;}
0 0
- (2016弱小联盟十一专场10.3) Help the Princess! BFS
- (2016弱小联盟十一专场10.3)Parentheses 找规律
- (2016弱小联盟十一专场10.3) Best Matched Pair 暴力
- Coins(弱小联盟十一专场)
- Help the Princess! BFS队列
- 2016弱校联盟十一专场10.3(12点场)
- 2016弱校联盟十一专场10.3,BNU52308,大模拟
- 2016弱校联盟十一专场10.3 C.We don't wanna work!(集合操作)
- 2016弱校联盟十一专场10.3 ABest Matched Pair(水)
- (2016 弱校联盟十一专场10.3) Similarity of Subtrees DFS + hash
- 2016 ACM-ICPC Asia Regional B – Help the Princess!(bfs)
- [JAG practice] B - Help the Princess! bfs
- Blocks(弱校联盟十一专场)
- UmBasketella(弱校联盟十一专场)
- 2016弱校联盟十一专场10.3 We don't wanna work!
- (2016弱校联盟十一专场10.5) F. Fibonacci of Fibonacci (暴力 + 循环节)
- 2016弱校联盟十一专场10.5(12点场) Increasing or Decreasing bnu 52325
- 2016弱校联盟十一专场10.5(12点场) Increasing or Decreasing
- django 1.8 官方文档翻译:logging
- Android快速自定义倒计时按钮
- EasyDarwin+ffmpeg进行PC(摄像头+麦克风)流媒体直播服务
- Volley尝试源码解析1
- 关于adb端口被占用
- (2016弱小联盟十一专场10.3) Help the Princess! BFS
- 学习:实现任意角度的sin、cos求值-No.1
- 正则表达式判断手机号
- 如何控制秒杀商品页面购买按钮的定时点亮
- Go语言编程入门
- ffmpeg推送,EasyDarwin转发,vlc播放 实现整个RTSP直播
- SWT常用组件列表及使用
- Nginx数据结构
- 模拟器、真机访问自己电脑的Tomcat