POJ 1979 解题报告
来源:互联网 发布:淘宝客app要自己做么 编辑:程序博客网 时间:2024/05/21 17:59
这道题是简单的DFS。感觉c++输入比较头疼。
1979Accepted728K0MSG++1846B/* ID: thestor1 LANG: C++ TASK: poj1979 */#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;const int MAXW = 20;const int MAXH = 20;int dr[4] = {-1, 0, 1, 0}, dc[4] = {0, 1, 0, -1};void DFS(int r, int c, const std::vector<string> &data, std::vector<std::vector<bool> > &visited, int &cnt, const int H, const int W){cnt++;visited[r][c] = true;// cout << "[debug]data[" << r << "][" << c << "]:" << data[r][c] << endl;int nr, nc;for (int d = 0; d < 4; ++d){nr = r + dr[d], nc = c + dc[d];if (0 <= nr && nr < H && 0 <= nc && nc < W && !visited[nr][nc] && data[nr][nc] == '.'){DFS(nr, nc, data, visited, cnt, H, W);}}}int main(){std::ios::sync_with_stdio(false);int W, H;std::vector<string> data(MAXH, string(MAXW, '.'));std::vector<std::vector<bool> > visited(MAXH, std::vector<bool>(MAXW, false));string line;int x, y;while (cin >> W >> H && W){// cout << "H: " << H << ", W: " << W << endl;for (int h = 0; h < H;){getline(cin, line);if (!line.size()){continue;}// cout << "[debug]line:[" << line << "]" << endl;for (int w = 0; w < W; ++w){data[h][w] = line[w];visited[h][w] = false;if (line[w] == '@'){x = h;y = w;}}++h;}// for (int r = 0; r < H; ++r)// {// for (int c = 0; c < W; ++c)// {// cout << data[r][c];// }// cout << endl;// }int cnt = 0;DFS(x, y, data, visited, cnt, H, W);cout << cnt << endl;}return 0; }
0 0
- POJ 1979 解题报告
- POJ 1979 Red and Black 解题报告
- 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解题报告
- POJ 1001解题报告
- POJ 1002解题报告
- GoAhead2.5源代码分析之6-访问验证(security.c) http状态码
- 8.2.3 在 F# 使用闭包捕获状态
- cocos2d-x lua physics
- 【问底】徐汉彬:Web系统大规模并发——电商秒杀与抢购
- Java 类注释文档编写方法
- POJ 1979 解题报告
- 数学知多少
- _IO, _IOR, _IOW, _IOWR 宏的用法与解析 2010-09-23 20:42:19
- cookie和session的区别
- CPU Overcommitment and Its Impact on SQL Server Performance on VMware
- 核心标签库
- C++ vector用法
- 位域的使用
- chrome js控制可编辑DIV光标移动到最后