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

求改错= =,到底哪里错了我,我的逻辑有问题吗,怎么都不对呢

Posted by Saleed at 2016-07-29 21:44:01 on Problem 2386
//POJ 2386 lake counting

#include<iostream>
using namespace std;
char field[200][200];
int dfs(int i,int j);
int row,col;
int main(){
	cin>>row>>col;
	for(int i=0;i<row;i++){
		for(int j=0;j<col;j++){
			cin>>field[i][j];
		}
	}
	int time=0;
	for(int i=0;i<row;i++){
		for(int j=0;j<col;j++){
			if(dfs(i,j)) time++;
		}
	}
	cout<<time<<endl;

}
int dfs(int i,int j){
	if(field[i][j]=='W'){
		field[i][j]='.';
		for(int dx=-1;dx<=1;dx++){
			for(int dy=-1;dy<=1;dy++){
				if(i+dx>=0&&i+dx<col&&j+dy>=0&&j+dy<row) dfs(i+dx,j+dy);
			}
		}
		return 1;
	}
	else return 0;
}

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