51nod 1416 两点
2017-07-30 00:24
316 查看
数据量比较小,dfs水过
#include <bits/stdc++.h> using namespace std; const int MAXN = 55; char g[MAXN][MAXN]; int book[MAXN][MAXN]; int n,m; bool mark = false; int dir[4][2] = {{0,1},{1,0},{0,-1},{-1,0}}; void dfs(int x, int y, int cnt) { if(mark) return; int tx,ty; for(int i = 0; i < 4; ++i) { tx = x + dir[i][0]; ty = y + dir[i][1]; if(g[tx][ty] == g[x][y] && book[tx][ty] == 0) { book[tx][ty] = 1; dfs(tx,ty,cnt+1); book[tx][ty] = 0; } else if(g[tx][ty] == g[x][y] && book[tx][ty] == 2) { if((cnt+1) >= 4) { mark = true; return; } } } } int main() { scanf("%d %d",&n,&m); for(int i = 0; i < n; ++i) scanf(" %s",g[i]); for(int i = 0; i < n; ++i) { for(int j = 0; j < m; ++j) { book[i][j] = 2; dfs(i,j,1); if(mark) { printf("Yes\n"); return 0; } book[i][j] = 0; } } printf("No\n"); return 0; }
相关文章推荐
- 51nod 1416 两点 【dfs+特殊判断】
- 51nod 1416 两点【并查集】
- 51NOD 1416 两点
- 51Nod - 1416 两点(搜索)
- 51Nod -1416 两点(dfs)
- 51nod 1416 两点(DFS)
- 1416 两点 51NOD
- 51Nod - 1416 两点
- 51nod 1416 两点
- 51nod 1416两点DFS
- 51nod 1416:两点 深搜
- 51Nod 1416 两点
- 51nod 1416:两点 深搜
- 51NOD 1416 两点 【水】DFS
- 51nod 1416 两点 (dfs)
- 51Nod - 1416 深度优先搜索
- 51nod 1416【DFS】
- 51Nod - 1416 搜索环
- 两点(51nod 1416)
- 1416 两点(dfs)