hdu1312
来源:互联网 发布:怀来大数据产业园 编辑:程序博客网 时间:2024/06/06 03:28
搜索
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <map>
#include <iterator>
#include <cstring>
#include <cmath>
using namespace std;
char maze[105][105];
int m, n;
int num;
int visit[105][105];
int dx[] = {-1,1,0,0}, dy[] = {0,0,-1,1};
class point {
public:
int x;
int y;
point(int x, int y) {
this->x = x, this->y = y;
}
};
vector<point> oils;
int isvalid(int x, int y) {
return x >=0 && y >=0 && x <m && y <n && !visit[x][y] && maze[x][y] == '.';
}
void dfs(int x, int y) {
int nx, ny;
for (int i = 0; i < 4; i++) {
nx = x+dx[i], ny = y+dy[i];
if (isvalid(nx, ny)) {
visit[nx][ny] = 1;
num++;
dfs(nx, ny);
}
}
}
int main() {
while (cin >> n >> m && (m||n)) {
oils.clear();
int bx, by;
for (int i = 0; i < m; i++) {
cin >> maze[i];
for (int j = 0; j < n; j++) {
if (maze[i][j] == '@')
bx = i, by = j;
}
}
memset(visit, 0, sizeof(visit));
num = 1;
visit[bx][by] = 1;
dfs(bx, by);
cout << num << endl;
}
return 0;
}
- hdu1312
- hdu1312
- HDU1312
- hdu1312
- hdu1312
- hdu1312
- hdu1312
- hdu1312
- hdu1312
- hdu1312
- hdu1312
- HDU1312
- HDU1312
- hdu1312
- hdu1312
- HDU1312
- hdu1312
- hdu1312深搜!!!
- Android ContentProvider
- leetcode 072 —— Edit Distance
- Algorithms—226.Summary Ranges
- 20150730
- pjsip在vs2013中编译和使用
- hdu1312
- 场景管理:BSP算法C++实现
- hdoj 1551 Cable master
- 双端队列链式实现完整代码
- HTML5_自定义数据类型
- uva 572
- 离散事件模拟-银行管理(模拟题,队列)
- 字符串最后一个单词的长度
- Android中引用style资源