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 bingshen at 2010-08-22 02:26:28 on Problem 1164
Source Code

Problem: 1164  User: bingshen 
Memory: 184K  Time: 16MS 
Language: C++  Result: Accepted 

Source Code 
#include<iostream>

using namespace std;

int map[60][60]={0};
bool use[60][60]={0};
int n,m;

int dfs(int i,int j)
{
	if(use[i][j]==0)
	{
		use[i][j]=1;
		switch(map[i][j])
		{
		case 0:
			return dfs(i+1,j)+dfs(i-1,j)+dfs(i,j+1)+dfs(i,j-1)+1;
			break;
		case 1:
			return dfs(i+1,j)+dfs(i,j+1)+dfs(i-1,j)+1;
			break;
		case 2:
			return dfs(i+1,j)+dfs(i,j+1)+dfs(i,j-1)+1;
			break;
		case 3:
			return dfs(i+1,j)+dfs(i,j+1)+1;
			break;
		case 4:
			return dfs(i+1,j)+dfs(i-1,j)+dfs(i,j-1)+1;
			break;
		case 5:
			return dfs(i+1,j)+dfs(i-1,j)+1;
			break;
		case 6:
			return dfs(i+1,j)+dfs(i,j-1)+1;
			break;
		case 7:
			return dfs(i+1,j)+1;
			break;
		case 8:
			return dfs(i-1,j)+dfs(i,j+1)+dfs(i,j-1)+1;
			break;
		case 9:
			return dfs(i-1,j)+dfs(i,j+1)+1;
			break;
		case 10:
			return dfs(i,j+1)+dfs(i,j-1)+1;
			break;
		case 11:
			return dfs(i,j+1)+1;
			break;
		case 12:
			return dfs(i-1,j)+dfs(i,j-1)+1;
			break;
		case 13:
			return dfs(i-1,j)+1;
			break;
		case 14:
			return dfs(i,j-1)+1;
			break;
		case 15:
			return 1;
			break;
		}
	}
	return 0;
}

int main()
{
	int i,j,max=0,count=0,s;
	scanf("%d%d",&n,&m);
	for(i=0;i<n;i++)
		for(j=0;j<m;j++)
			scanf("%d",&map[i][j]);
	for(i=0;i<n;i++)
		for(j=0;j<m;j++)
		{
			if(use[i][j]==0)
			{
				s=dfs(i,j);
				if(s>=max)
				{
					max=s;
				}
				count++;
			}
		}
	printf("%d\n%d\n",count,max);
	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