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 boluor at 2008-12-25 11:49:19 on Problem 2386
我是在数组的周围加了一圈干地,方便些。然后如果是干地就略过,如果是湖,就数量++,并且递归搜索他所有相邻的湖,将相邻的标记为干地。
[code]
#include <iostream>
using namespace std;

char arr[200][200];
void rec(int i,int j);
int main(){
	int m,n;
	int i,j,k;
	while(scanf("%d%d",&m,&n)!=EOF){

	for(i=0;i<m+2;i++)	arr[i][0]=arr[i][n+1]='.';
	for(j=0;j<n+2;j++)	arr[0][j]=arr[m+1][j]='.';

	char s[200];
	for(i=1;i<=m;i++){
			scanf("%s",s);
			for(j=1;j<=n;j++){
				arr[i][j]=s[j-1];
			}
	}
	/*
	printf("---------start-------\n");
	for(i=0;i<m+2;i++){
		printf("%s\n",arr[i]);
	}
	printf("---------end--------\n");
        */
	int count=0;
	for(i=0;i<m;i++){
		for(j=0;j<n;j++){
			if(arr[i][j]=='W'){
				count++;
				rec(i,j);
			}
		}
	}
	printf("%d\n",count);
	}
	return 0;
}

void rec(int i,int j){
	if(arr[i][j]=='.')	return;
	else	arr[i][j]='.';
	rec(i-1,j);
	rec(i-1,j-1);
	rec(i-1,j+1);
	rec(i,j-1);
	rec(i,j+1);
	rec(i+1,j-1);
	rec(i+1,j);
	rec(i+1,j+1);
}
[/code]

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