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 |
我的也是 Output Limit Exceeded啊//哪位给侃侃 #include<iostream> #include<string> char oil[101][101]; int a[101][101]; int m,n; void dfs(int si,int sj){ a[si][sj]=0; if(oil[si-1][sj]=='@'&&a[si-1][sj]&&si-1>=0&&si-1<=m&&sj>=0&&sj<=n) dfs(si-1,sj); if(oil[si+1][sj]=='@'&&a[si+1][sj]&&si+1>=0&&si+1<=m&&sj>=0&&sj<=n) dfs(si+1,sj); if(oil[si][sj-1]=='@'&&a[si][sj-1]&&si>=0&&si<=m&&sj-1>=0&&sj-1<=n) dfs(si,sj-1); if(oil[si][sj+1]=='@'&&a[si][sj+1]&&si>=0&&si<=m&&sj+1>=0&&sj+1<=n) dfs(si,sj+1); if(oil[si+1][sj+1]=='@'&&a[si+1][sj+1]&&si+1>=0&&si+1<=m&&sj+1>=0&&sj+1<=n) dfs(si+1,sj+1); if(oil[si-1][sj-1]=='@'&&a[si-1][sj-1]&&si-1>=0&&si-1<=m&&sj-1>=0&&sj-1<=n) dfs(si-1,sj-1); if(oil[si-1][sj+1]=='@'&&a[si-1][sj+1]&&si-1>=0&&si-1<=m&&sj+1>=0&&sj+1<=n) dfs(si-1,sj+1); if(oil[si+1][sj-1]=='@'&&a[si+1][sj-1]&&si+1>=0&&si+1<=m&&sj-1>=0&&sj-1<=n) dfs(si+1,sj-1); //} } using namespace std; int main() { while(1){ cin >> m >> n; if(m==0&&n==0) break; int i; //memset(a,0,sizeof(a)); for(i=0;i<n;i++) for(int j=0;j<m;j++)a[i][j]=1; for(i=0;i<m;i++) { scanf("%s",&oil[i]); } int count=0; for( i=0; i< m; i++ ) for(int j=0;j<n; j++ ) if(a[i][j]&&oil[i][j]=='@') { count++; dfs(i,j); } printf("%d\n",count); } return 0; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator