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 chenxuan123456789 at 2012-07-30 18:46:52 on Problem 2386
#include <stdio.h>
#define M 100+10
char map[M][M];
int r,c;
int d[8][2]={{1,1},{1,0},{1,-1},{0,1},{0,-1},{-1,-1},{-1,0},{-1,1}};
int times,flag;
void dfs(int s,int t)
{
	int i,tempx,tempy;
	if(map[s][t]=='W')
	{
		map[s][t]='.';
		flag=1;
		for(i=0;i<8;i++)
		{
			tempx=s+d[i][0];
			tempy=t+d[i][1];
			if(tempx>=1&&tempx<=r&&tempy>=1&&tempy<=c&&map[tempx][tempy]=='W')
				dfs(tempx,tempy);
		}
	}
}
int main()
{
	int i,j;
	scanf("%d%d",&r,&c);
	for(i=1;i<=r;i++)
	{
		getchar();
		for(j=1;j<=c;j++)
			scanf("%c",&map[i][j]);
	}
	times=0;
	for(i=1;i<=r;i++)
		for(j=1;j<=c;j++)
		{
			flag=0;
			dfs(i,j);
			if(flag)
			times++;
		}
		printf("%d\n",times);
		return 1;
}

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