【洛谷 1363】 幻象迷宫
来源:互联网 发布:广州海颐软件 编辑:程序博客网 时间:2024/04/29 17:13
思路
数组的下表要从0开始存,取膜的时候可以采用:
代码
#include <cstdio>#include <iostream>using namespace std;const int inf = 1e9;char ch[1510][1510];int vis[1510][1510][2], x1, y1, n, m;int b1[]={0,1,-1,0,0};int b2[]={0,0,0,1,-1};bool dfs(int x, int y){ int xx = ((x%n)+n)%n; int yy = ((y%m)+m)%m; if(ch[xx][yy] == '#') return false; if(vis[xx][yy][0] != inf) return vis[xx][yy][0] != x || vis[xx][yy][1] != y; vis[xx][yy][0] = x, vis[xx][yy][1] = y; for(int i = 1; i <= 4; i ++) if(dfs(x+b1[i], y+b2[i])) return true; return false;}int main(){ while(scanf("%d%d", &n, &m) == 2){ for(int i = 0; i <= n; i ++) for(int j = 0; j <= m; j ++) vis[i][j][0] = vis[i][j][1] = inf; for(int i = 0; i < n; i ++) scanf("%s", ch[i]); for(int i = 0; i < n; i ++) for(int j = 0; j < m; j ++) if(ch[i][j] == 'S') x1 = i, y1 = j; if(dfs(x1,y1))printf("Yes\n"); else printf("No\n"); } return 0;}
0 0
- 【洛谷 1363】 幻象迷宫
- 幻象迷宫
- 1075:幻象迷宫
- 幻象
- 【jzoj4756】【幻象】
- Jzoj4756 幻象
- mysql 幻象读
- 14.2.2.5 幻象读
- 【NOIP模拟】幻象
- 一个幻象读的例子
- NOIP提高组模拟 幻象
- 【NOIP提高组模拟】幻象
- [洛谷1605]迷宫
- 洛谷P1141 01迷宫
- 洛谷P1238 走迷宫
- 洛谷P1141 01迷宫
- |洛谷|DFS|P1605 迷宫
- 洛谷 1605 迷宫
- Windows电脑重装系统亲身经历
- 字符串倒置 in C
- 记录一次core文件调试
- myeclise svn 同步报错
- hdoj 3015 Disharmony Trees(树状数组)
- 【洛谷 1363】 幻象迷宫
- 拓展方法
- leetcode 160. Intersection of Two Linked Lists
- HTTP协议
- Springboot 404 500错误页面处理
- printf的宏定义版本及多重使用方法
- question:setValue:forUndefinedKey: this class is not key value coding-compliant for the key
- java缓冲流,数据流和对象流
- 最流行的Java工具总结