acwing3红与黑
生活随笔
收集整理的這篇文章主要介紹了
acwing3红与黑
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
紅與黑
紅與黑
bfs
dfs
#include <iostream>using namespace std;const int N = 25;int n, m; char g[N][N]; int dx[] = {-1, 0, 1, 0}, dy[] = {0, 1, 0, -1};int dfs(int x, int y) {int res = 1;g[x][y] = '#';for (int i = 0; i < 4; i ++ ){int a = x + dx[i], b = y + dy[i];if (a >= 0 && a < n && b >= 0 && b < m && g[a][b] == '.')res += dfs(a, b);}return res; }int main() {while (cin >> m >> n, n || m){for (int i = 0; i < n; i ++ ) cin >> g[i];int x, y;for (int i = 0; i < n; i ++ )for (int j = 0; j < m; j ++ )if (g[i][j] == '@'){x = i;y = j;}cout << dfs(x, y) << endl;}return 0; }總結
以上是生活随笔為你收集整理的acwing3红与黑的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 基于体素的3D目标检测网络:VoxelN
- 下一篇: 庆幸