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

我的也是 Output Limit Exceeded啊

Posted by lxc0601 at 2007-12-10 11:10:24 on Problem 1562
//哪位给侃侃

#include<iostream>
#include<string>

char oil[101][101];
int a[101][101];
int m,n;

void dfs(int si,int sj){
		
	a[si][sj]=0;

			if(oil[si-1][sj]=='@'&&a[si-1][sj]&&si-1>=0&&si-1<=m&&sj>=0&&sj<=n)
				dfs(si-1,sj);
			if(oil[si+1][sj]=='@'&&a[si+1][sj]&&si+1>=0&&si+1<=m&&sj>=0&&sj<=n)
				dfs(si+1,sj);
			if(oil[si][sj-1]=='@'&&a[si][sj-1]&&si>=0&&si<=m&&sj-1>=0&&sj-1<=n)
				dfs(si,sj-1);
			if(oil[si][sj+1]=='@'&&a[si][sj+1]&&si>=0&&si<=m&&sj+1>=0&&sj+1<=n)
				dfs(si,sj+1);
			if(oil[si+1][sj+1]=='@'&&a[si+1][sj+1]&&si+1>=0&&si+1<=m&&sj+1>=0&&sj+1<=n)
				dfs(si+1,sj+1);
			if(oil[si-1][sj-1]=='@'&&a[si-1][sj-1]&&si-1>=0&&si-1<=m&&sj-1>=0&&sj-1<=n)
				dfs(si-1,sj-1);
			if(oil[si-1][sj+1]=='@'&&a[si-1][sj+1]&&si-1>=0&&si-1<=m&&sj+1>=0&&sj+1<=n)
				dfs(si-1,sj+1);
			if(oil[si+1][sj-1]=='@'&&a[si+1][sj-1]&&si+1>=0&&si+1<=m&&sj-1>=0&&sj-1<=n)
				dfs(si+1,sj-1);

//}
}
using namespace std;

int main()
{
	while(1){
		cin >> m >> n;
	if(m==0&&n==0)
		break;
	int i;

	//memset(a,0,sizeof(a));
	for(i=0;i<n;i++)
			for(int j=0;j<m;j++)a[i][j]=1;
	for(i=0;i<m;i++)
	{
		scanf("%s",&oil[i]);
	}

int count=0;
	for( i=0; i< m; i++ )
		for(int j=0;j<n; j++ )
			if(a[i][j]&&oil[i][j]=='@')
			{
				count++;
				dfs(i,j);
			}	
printf("%d\n",count);

	}
	
	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