ZOJ 2165 Red and Black
来源:互联网 发布:中科院人工智能芯片 编辑:程序博客网 时间:2024/05/21 11:41
题目
简单搜索,注意W,H各表示什么;
#include <iostream>#include <cstring>#include <cstdio>using namespace std;const int MAXN = 25;char map1[MAXN][MAXN];int W, H;int stepnum;int dir[4][2] = { {-1, 0}, {0, 1}, {1, 0}, {0, -1} };bool Cango(int x, int y){ if(x >= 0 && y >= 0 && x < H && y < W && map1[x][y] != '#') return true; else return false;}void DFS( int x, int y){ stepnum++; map1[x][y] = '#'; for(int i = 0; i < 4; ++i) { int xx = x + dir[i][0]; int yy = y + dir[i][1]; if( Cango(xx, yy) ) DFS(xx, yy); }}int main(){ int i, j; int si, sj; while((cin>>W>>H) && W && H) { for(i = 0; i < H; ++i) { for(j = 0; j < W; ++j) { cin>>map1[i][j]; if(map1[i][j] == '@') si = i, sj = j; } } stepnum = 0; DFS(si, sj); cout<<stepnum<<endl; } return 0;}/**6 9....#......#..............................#@...#.#..#.11 9.#..........#.#######..#.#.....#..#.#.###.#..#.#..@#.#..#.#####.#..#.......#..#########............11 6..#..#..#....#..#..#....#..#..###..#..#..#@...#..#..#....#..#..#..7 7..#.#....#.#..###.###...@...###.###..#.#....#.#..0 0*/
- zoj 2165 Red and Black
- ZOJ-2165 red and black
- ZOJ-2165 Red and Black
- zoj 2165 Red and Black
- ZOJ 2165 Red and Black
- ZOJ 2165 Red and Black
- zoj 2165(hdu1312) Red and Black(深搜)
- poj 1979 zoj 2165 Red and Black
- zoj 2165 Red and Black (BFS)
- ZOJ 2165 Red and Black (floodfill)
- ZOJ Problem Set - 2165 Red and Black
- zoj 2165 || poj 1979 Red and Black(BFS水水)
- poj 1979 zoj 2165 Red and Black 深搜做法
- zoj 2165||poj 1979 red and black (dfs)
- POJ 1979 Red and Black (zoj 2165) DFS
- ZOJ 2165 POJ 1979 Red and Black DFS水题
- ZOJ 2165 Red and Black(DFS,水题)
- Red and Black
- ZeroMemory
- 在局域網ubuntu中安裝G++環境
- WPF学习心得
- vb中提交事务(整理)
- 二维计算几何模板整理
- ZOJ 2165 Red and Black
- [DBNETLIB][ConnectionOpen(connect()).]SQL Server 不存在或拒绝访问的一种原因
- 字符数组的初始化
- memset
- spfa poj 3259
- hdu 3698 Let the light guide us(线段树优化&简单DP)
- split用法,区别一个或多个空格
- 黑马程序员_交通灯管理系统学习笔记
- [CF 351B]Jeff and Furik[归并排序求逆序数]