poj2386Lake Counting之dfs
来源:互联网 发布:网络侦探 2周目 彩蛋 编辑:程序博客网 时间:2024/06/06 02:27
分析:朝八个方向搜索,入门题
/** Filename: code.cpp* Created: 2017-10-26* Author: wyl6 *[mail:17744454343@163.com]* Desciption: Desciption*/#include <cstdio>#include <cstdlib>#include <iostream>#include <stack>#include <queue>#include <algorithm>#include <cstring>#include <string>#include <cmath>#include <vector>#include <bitset>#include <list>#include <sstream>#include <set>#include <functional>using namespace std;#define INF 0x3f3f3f3f#define MAX 100typedef long long ll;int n,m,ans;char map[105][105];int hor[8] = {1,-1,0,0,1,-1,1,-1};int ver[8] = {0,0,1,-1,-1,1,1,-1};void dfs(int x,int y){map[x][y] = '.';for (int i = 0; i < 8; i += 1){int nx = x+hor[i];int ny = y+ver[i];if (nx >=0 && ny >= 0 && nx < n && ny < m && map[nx][ny] != '.'){dfs(nx,ny);}}}int main(int argc, char const* argv[]){#ifndef ONLINE_JUDGE freopen("in.txt", "r", stdin); freopen("out.txt", "w", stdout);#endifwhile (cin >> n >> m){ans = 0;for (int i = 0; i < n; i += 1){for (int j = 0; j < m; j += 1){cin >> map[i][j];}}for (int i = 0; i < n; i += 1){for (int j = 0; j < m; j += 1){if(map[i][j] != '.') {dfs(i,j);ans++;}}}printf("%d\n",ans);}return 0;}
阅读全文
0 0
- poj2386Lake Counting之dfs
- poj2386Lake Counting(dfs)
- poj2386Lake Counting(DFS算法)
- poj2386Lake Counting
- poj2386Lake Counting
- POJ2386Lake Counting
- DFS 之 poj 2386 Lake Counting
- DFS深度优先搜索之lake counting
- Lake Counting(搜索之DFS)
- POJ2386:Lake Counting(DFS)
- HDU2952:Counting Sheep(DFS)
- hdu2952(DFS Counting Sheep )
- poj2386 Lake Counting DFS
- POJ - Lake Counting(DFS)
- Lake Counting DFS水题
- HDU2952:Counting Sheep(DFS)
- Lake Counting(DFS)
- DFS------Lake Counting
- Dictionary<TKey, TValue> 散列集合
- 1036. 跟奥巴马一起编程(15)
- HDU 5542 The Battle of Chibi(dp+树状数组)
- java中jdbc连接数据库操作
- python运算题
- poj2386Lake Counting之dfs
- 1037. 在霍格沃茨找零钱(20)
- JDBC
- PHP单例模式
- 异常及其解决
- 计算机网络第3章 数据链路层
- 自产生程序
- 致给迷茫与失落时的的自己
- linux学习之rpm命令