1 solutions
-
0
C++ :
#include<cstdio> #include<iostream> #include<cmath> #include<cstring> #include<algorithm> #include<queue> #include<vector> #include<map> using namespace std; char cMap[105][105]; int vis[105][105]; int N, M; int dir[][2] = {-1, 0, 0, -1, 1, 0, 0, 1, -1, -1, -1, 1, 1, -1, 1, 1}; int can(int x, int y){ if(!vis[x][y] && cMap[x][y] == '$') return 1; return 0; } void dfs(int x, int y){ vis[x][y] = 1; for(int i = 0; i < 8; i++){ int tx = x + dir[i][0]; int ty = y + dir[i][1]; if(can(tx, ty)) dfs(tx, ty); } } int main(){ //freopen("in.txt", "r", stdin); while(scanf("%d%d", &N, &M) && (N || M)){ int cnt = 0; memset(vis, 0, sizeof(vis)); for(int i = 0; i < N; i ++){ scanf("%s", cMap[i]); } for(int i = 0; i < N; i++) for(int j = 0; j < M; j++){ if(!vis[i][j] && cMap[i][j] == '$'){ cnt++; dfs(i, j); } } cout <<cnt <<endl; } return 0; }
- 1
Information
- ID
- 667
- Time
- 1000ms
- Memory
- 128MiB
- Difficulty
- (None)
- Tags
- # Submissions
- 0
- Accepted
- 0
- Uploaded By