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 |
过了贴代码攒rp#include <iostream> #include <cstdio> #include <cstring> using namespace std; int data[101][101]; int x[10001],y[10001]; const int around[8][2]={{0,1},{1,0},{1,1},{0,-1},{-1,0},{-1,-1},{1,-1},{-1,1}}; int num,m,n,sum; void dfs(int kx,int ky) { int p,q; data[kx][ky]=num; for(int i=0;i<9;i++) { p=kx+around[i][0]; q=ky+around[i][1]; if(p<0||q<0||p>m-1||q>n-1){continue;} else if(data[p][q]==-1){dfs(p,q);} } return; } int main() { while(cin>>m>>n) { if(!n&&!m){break;} num=1; memset(data,0,sizeof(data)); memset(x,0,sizeof(x)); memset(y,0,sizeof(y)); sum=0;char c[n]; for(int i=0;i<m;i++) { scanf("%s",c); for(int j=0;j<n;j++) { if(c[j]=='@') { data[i][j]=-1; x[sum]=i;y[sum]=j; sum++; } } } for(int i=0;i<sum;i++) { if(data[x[i]][y[i]]!=-1){continue;} dfs(x[i],y[i]);num++; } num--; cout<<num<<endl; } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator