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 |
我没见过这么坑的题目,AC代码里说明#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #include<cmath> using namespace std; const int ms=101; bool vis[ms][ms]; char map[ms][ms]; //int dir[4][2]={0,1,1,0,0,-1,-1,0}; int n,m,ans; void input() { ans=0; scanf("%d%d",&n,&m); char c; /* getchar(); for(int i=0;i<n;i++) { for(int j=0;j<m;j++) scanf("%c",&map[i][j]); getchar(); } */ for(int i=0;i<n;i++) { for(int j=0;j<m;j++) { while(c=getchar(),c!='*'&&c!='@'); map[i][j]=c; } } memset(vis,0,sizeof(vis)); return ; } int dfs(int x,int y) { vis[x][y]=1; if(x>=0&&x<n&&y+1>=0&&y+1<m&&vis[x][y+1]==0&&map[x][y+1]=='@') dfs(x,y+1); if(x+1>=0&&x+1<n&&y+1>=0&&y+1<m&&vis[x+1][y+1]==0&&map[x+1][y+1]=='@') dfs(x+1,y+1); if(x+1>=0&&x+1<n&&y>=0&&y<m&&vis[x+1][y]==0&&map[x+1][y]=='@') dfs(x+1,y); if(x+1>=0&&x+1<n&&y-1>=0&&y-1<m&&vis[x+1][y-1]==0&&map[x+1][y-1]=='@') dfs(x+1,y-1); if(x>=0&&x<n&&y-1>=0&&y-1<m&&vis[x][y-1]==0&&map[x][y-1]=='@') dfs(x,y-1); if(x-1>=0&&x-1<n&&y-1>=0&&y-1<m&&vis[x-1][y-1]==0&&map[x-1][y-1]=='@') dfs(x-1,y-1); if(x-1>=0&&x-1<n&&y>=0&&y<m&&vis[x-1][y]==0&&map[x-1][y]=='@') dfs(x-1,y); if(x-1>=0&&x-1<n&&y+1>=0&&y+1<m&&vis[x-1][y+1]==0&&map[x-1][y+1]=='@') dfs(x-1,y+1); return 1; } int main() { while(1) { input(); if(n+m==0) break; for(int i=0;i<n;i++) for(int j=0;j<m;j++) if(vis[i][j]==0&&map[i][j]=='@') ans+=dfs(i,j); printf("%d\n",ans); } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator