2 条题解
-
-1
#include <bits/stdc++.h> using namespace std; const int N = 1e2 + 10; char a [N] [N]; int m , n , k , q , w; int xx [4] = {-1 , 1 , 0 , 0}; int yy [4] = {0 , 0 , 1 , -1}; bool f (int c , int d) { if (a [c] [d] == '.' && c >= 1 && c <= n && d >= 1 && d <= m) { return 1; } return 0; } void dfs (int x , int y) { a [x] [y] = '#'; for (int i = 0; i < 4; i++) { int nx = x + xx [i]; int ny = y + yy [i]; if (f (nx , ny)) { k++; dfs (nx , ny); } } } int main() { while (cin >> m >> n) { if (m == 0 && n == 0) { break; } for (int i = 1; i <= n; i++) { for (int j = 1; j <= m; j++) { cin >> a [i] [j]; if (a [i] [j] == '@') { q = i; w = j; } } } k = 1; dfs(q,w); cout << k << endl; } return 0; }
信息
- ID
- 3004
- 时间
- 1000ms
- 内存
- 256MiB
- 难度
- 3
- 标签
- 递交数
- 364
- 已通过
- 88
- 上传者