zoj 1047
2012-05-02 22:06
267 查看
#include <stdio.h> #include <cstdlib> #include <iostream> #include <string> #include <string.h> #include <algorithm> using namespace std; char map[25][25]; bool vis[25][25]; int n, m, a, b; int len; int dir[4][2] = {-1,0, 0,1, 1,0, 0,-1}; int dir_x[4][2] = {-1,-1, -1,1, 1,1, 1,-1}; void init(int n, int m) { memset(vis, false,sizeof(vis)); memset(map,'.',sizeof(map)); len = 0; char str[25]; for(int i=1; i<=n; i++) { scanf("%s",str); for(int j=1; j<=m; j++) map[i][j] = str[j-1]; } } void dfs(int x, int y) { vis[x][y] = true; for(int i=0; i<4; i++) { int x0 = x+dir[i][0]; int y0 = y+dir[i][1]; if(!vis[x0][y0]&&map[x0][y0]=='X') dfs(x0,y0); else if(!vis[x0][y0]&&map[x0][y0]=='.') len++; //dfs(x,y,len+1); } for(int i=0; i<4; i++) { int x0 = x + dir_x[i][0]; int y0 = y + dir_x[i][1]; if(!vis[x0][y0]&&map[x0][y0]=='X') dfs(x0,y0); } } int main() { while(scanf("%d",&n)&&n) { scanf("%d%d%d",&m, &a, &b); init(n,m); dfs(a,b); printf("%d\n",len); } system("pause"); return 0; }
相关文章推荐
- ZOJ1047-Image Perimeters
- poj 1111||zoj 1047 Image Perimeters(dfs)
- ZOJ 1047 Image Perimeters(BFS搜索)
- zoj 1047 || poj 1111 Image Perimeters(DFS water~)
- zoj-1047-I Think I Need a Houseboat
- ZOJ-1047 image primeters
- ZOJ 1047 Image Perimeters
- ZOJ-1047
- C语言中的求图像周长问题(ZOJ 1047)
- ZOJ 1047 物体堆的边界
- ZOJ 1047 Image Perimeters
- ZOJ 1047 Image Perimeters (dfs)
- zoj&nbsp;1047&nbsp;Image&nbsp;Perimeters
- ZOJ 1047 Image Perimeters
- ZOJ 1047 Image Perimeters
- zoj 1047 (bfs)
- 深度优先搜索-ZOJ 1047 Image Perimeters
- HDU 1047 || ZOJ 1292 大数相加
- ZOJ - 1047 Image Perimeters
- ZOJ 1047 Image Perimeters(dfs+技巧)