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 |
123456#include<iostream> using namespace std; int b[101][101]={0}; char a[101][101]; int num[8][2]={{-1,-1},{-1,0},{-1,1},{0,-1},{0,1},{1,-1},{1,0},{1,1}}; int m,n; void make(int t,int s) { int i; int j,k; b[t][s]=1; for(i=0;i<8;i++) { j=t+num[i][0]; k=s+num[i][1]; if((a[j][k]=='W')&&(b[j][k]==0)&&(j>=0) &&(j<m)&&(k>=0)&&(k<n)) make(j,k); } } int main() { int i,j; cin>>m>>n; for(i=0;i<m;i++) { for(j=0;j<n;j++) cin>>a[i][j]; } int c=0; for(i=0;i<m;i++) { for(j=0;j<n;j++) { if(a[i][j]=='W'&&b[i][j]==0) { c++; make(i,j); } } } cout<<c<<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