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 |
贴个代码~~~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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator