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

咋都喜欢用广搜,深搜不简单吗?附AC小代码

Posted by sbtdkj1017 at 2011-11-17 10:41:07 on Problem 1111
In Reply To:BFS一次AC o(∩_∩)o 附代码 Posted by:lsz at 2011-05-05 16:31:20
#include<iostream>
#include<cstdlib>

using namespace std;

int perimeter;
char g[22][22];

void dfs(int x,int y,bool flag)
{
	if(g[x][y]=='.'&&flag)perimeter++;
	if(g[x][y]!='X')return;
	g[x][y]=0;
	for(int i=x-1;i<=x+1;i++)
	for(int j=y-1;j<=y+1;j++)
		dfs(i,j,(i-x+j-y)%2);
}

int main()
{
	int i,j,r,c,x,y;
	while(cin>>r>>c>>x>>y,r+c+x+y)
	{
		memset(g,'.',sizeof(g));
		for(i=1;i<=r;i++)
		for(j=1;j<=c;j++)
			cin>>g[i][j];
		perimeter=0;
		dfs(x,y,false);
		cout<<perimeter<<endl;
	}
    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