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

麻烦各位帮忙看看,各种WA。。。。。。

Posted by sjjwind at 2011-04-16 09:41:51 on Problem 1154
#include <iostream>
#include <cstdlib>
#include <string>
#define N 30
using namespace std;
char str[N][N];
int ans;
int row,col;
int arr[N];
void dfs(int x,int y);
int main()
{	
	int i,j;	
	int num;
	while(cin>>row>>col)
	{
		
		for(i=0;i<N;i++)
			arr[i]=1;
		ans=0;
		for(i=0;i<row;i++)
			for(j=0;j<col;j++)
				cin>>str[i][j];
		dfs(0,0);
		cout<<ans<<endl;	
	}	
}	
void dfs(int x,int y)
{
	ans++;
	arr[str[x][y]-'A']=0;
	str[x][y]='.';
	if(x+1<row&&str[x+1][y]!='.'&&arr[str[x+1][y]-'A'])
		dfs(x+1,y);
	if(y+1<col&&str[x][y+1]!='.'&&arr[str[x][y+1]-'A'])
		dfs(x,y+1);
	if(x-1>=0&&str[x-1][y]!='.'&&arr[str[x-1][y]-'A'])
		dfs(x-1,y);
	if(y-1>=0&&str[x][y-1]!='.'&&arr[str[x][y-1]-'A'])	
		dfs(x,y-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