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 |
不解啊!!!wa了好几次#include <stdio.h> #include <string.h> char map[101][101]; int n,m; //int move[8][2]={{1,0},{-1,0},{0,1},{0,-1},{1,1},{-1,1},{1,-1},{-1,-1}}; void dfs(int x,int y) { map[x][y]='.'; for(int dx=-1;dx<=1;dx++) for(int dy=-1;dy<=1;dy++) { int nx=x+dx,ny=y+dy; if(0<=nx&&nx<n&&0<=ny&&ny<m&&map[nx][ny]=='W') dfs(nx,ny); } } int main() { int sum=0; memset(map,0,sizeof(map)); scanf("%d%d",&n,&m); for(int i=0;i<n;i++) for(int j=0;j<m;j++) scanf("%c",&map[i][j]);//为什么这样的输入不能ac //for(int i=0;i<n;i++) //scanf("%s",&map[i]); //改成这样就ac了 for(int i=0;i<n;i++) { for(int j=0;j<m;j++) { if(map[i][j]=='W') { dfs(i,j); sum++; } } } printf("%d\n",sum); return 0; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator