Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
麻烦各位帮忙看看,各种WA。。。。。。#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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator