POJ 2386 解题报告
来源:互联网 发布:无锡加工中心编程招聘 编辑:程序博客网 时间:2024/05/21 14:55
这道题是简单的DFS题。
2386Accepted548K0MSC++1230B/* ID: thestor1 LANG: C++ TASK: poj2386 */#include <iostream>#include <fstream>#include <cmath>#include <cstdio>#include <cstring>#include <limits>#include <string>#include <vector>#include <list>#include <set>#include <map>#include <queue>#include <stack>#include <algorithm>#include <cassert>using namespace std;int dx[8] = {-1, -1, 0, 1, 1, 1, 0, -1}, dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};void dfs(int r, int c, std::vector<std::vector<char> > &grid, const int N, const int M){grid[r][c] = 'X';for (int d = 0; d < 8; ++d){int nr = r + dx[d], nc = c + dy[d];if (0 <= nr && nr < N && 0 <= nc && nc < M && grid[nr][nc] == 'W'){dfs(nr, nc, grid, N, M);}}}int main(){int N, M;scanf("%d%d", &N, &M);std::vector<std::vector<char> > grid(N, std::vector<char>(M, '.'));char line[101];for (int i = 0; i < N; ++i){scanf("%s", line);for (int j = 0; j < M; ++j){grid[i][j] = line[j];}}int cnt = 0;for (int i = 0; i < N; ++i){for (int j = 0; j < M; ++j){if (grid[i][j] == 'W'){dfs(i, j, grid, N, M);cnt++;}}}printf("%d\n", cnt);return 0; }
0 0
- POJ 2386 解题报告
- POJ-2386-Lake Counting-解题报告
- poj 2386 Lake Counting 解题报告(BFS)
- poj解题报告——2386
- poj数百篇解题报告
- poj 1141解题报告
- poj 1001解题报告
- poj 1011 解题报告
- poj 1087 解题报告
- poj 2153解题报告
- poj 2051解题报告
- POJ 1167 解题报告
- poj 1026 解题报告
- POJ 1077 解题报告
- POJ 1042 解题报告
- POJ 1095 解题报告
- POJ 1159解题报告
- poj 2312解题报告
- 在android下运行arm gcc工具链编译出来的可执行文件
- 第十六周项目二用指针玩字符串任务一:字符串连接的完成(用指针作形参)
- 遍历Map的几种方式
- 【习题3-2】 UVA - 1586 Molar mass
- 安卓系统与苹果系统的区别
- POJ 2386 解题报告
- [HDOJ]2014
- 学习boost::asio(1)
- ubuntu上编译Android源码(Build Android source
- 第十六周项目二 用指针玩转字符串-项目目录
- 把苹果iPhone手机传文件传给安卓系统手机
- Codeforces Round #282 (Div. 2) C
- Struts2学习笔记——Struts框架的工作原理(源码调试)
- NANDFLASH学习 <s3c2440>