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

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

Posted by 3013216027 at 2014-07-22 09:09:32 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;
> }
和上面那家一样..地图大小最起码要开到100*101,因为题目说100字符,但是'\0'是要你来考虑的.发现童鞋们怎么这么抠,说了100就给100...开200会肿么样吖...

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator