Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
Register

## Re:求助啊！！ 为什么这么写会WA啊 试了好几次了 T T

Posted by great_yellow at 2013-10-28 23:48:48 on Problem 2386
In Reply To:求助啊！！ 为什么这么写会WA啊 试了好几次了 T T Posted by:cleantha at 2013-06-20 23:25:48
```> #include <iostream>
> using namespace std;
>
> const int MAX_N = 100;
> const int MAX_M = 100;
> static int counter = 0;
> char field[MAX_N][MAX_M];
>
> void dfs(int x, int y, int n, int m){
> 	field[x][y] = '.';
>
> 	for(int dx=-1; dx<=1; dx++){
> 		for(int dy=-1; dy<=1; dy++){
> 			int nx = x+dx;
> 			int ny = y+dy;
> 			if(nx>=0 && nx<n && ny>=0 && ny<m && field[nx][ny]=='w'){
> 				dfs(nx, ny, n, m);
> 			}
> 		}
> 	}
>
> 	return;
>
> }
>
> void solve(int n, int m){
> 	for(int i=0; i<n; i++){
> 		for(int j=0; j<m; j++){
> 			if(field[i][j] == 'w'){
> 				dfs(i, j, n, m);
> 				counter++;
> 			}
>
> 		}
> 	}
> }
>
> int main(void)
> {
> 	int N, M;
> 	char flag;
> 	cin>>N>>M;
>
> 	if(N<MAX_N && M<MAX_M){
> 		for(int i=0; i<N; i++){
> 			for(int j=0; j<M; j++){
> 				cin>>flag;
> 				field[i][j] = flag;
> 			}
> 		}
>
> 	}
>
> 	solve(N, M);
> 	int output = counter;
> 	cout<<output<<endl;
>
> 	return 0;
> }

Followed by: