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 |
代码!#include <stdio.h> #define M 100+10 char map[M][M]; int r,c; int d[8][2]={{1,1},{1,0},{1,-1},{0,1},{0,-1},{-1,-1},{-1,0},{-1,1}}; int times,flag; void dfs(int s,int t) { int i,tempx,tempy; if(map[s][t]=='W') { map[s][t]='.'; flag=1; for(i=0;i<8;i++) { tempx=s+d[i][0]; tempy=t+d[i][1]; if(tempx>=1&&tempx<=r&&tempy>=1&&tempy<=c&&map[tempx][tempy]=='W') dfs(tempx,tempy); } } } int main() { int i,j; scanf("%d%d",&r,&c); for(i=1;i<=r;i++) { getchar(); for(j=1;j<=c;j++) scanf("%c",&map[i][j]); } times=0; for(i=1;i<=r;i++) for(j=1;j<=c;j++) { flag=0; dfs(i,j); if(flag) times++; } printf("%d\n",times); return 1; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator