Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
求助啊!! 为什么这么写会WA啊 试了好几次了 T T#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:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator