标签:des style blog ar io color os sp for
Description
Input
Output
Sample Input
Sample Output
#include <cstdio> #include <cmath> #include <cstring> #include <ctime> #include <iostream> #include <algorithm> #include <set> #include <vector> #include <sstream> #include <queue> #include <typeinfo> #include <fstream> typedef long long ll; using namespace std; //freopen("D.in","r",stdin); //freopen("D.out","w",stdout); #define sspeed ios_base::sync_with_stdio(0);cin.tie(0) #define maxn 100 const int inf=0x7fffffff; //无限大 int dx[8]={1,-1,0,0,1,-1,1,-1}; int dy[8]={0,0,1,-1,1,-1,-1,1}; int vis[120][120]; int n,m; int ans=0; struct point { int x; int y; }; void bfs(int x,int y) { if(vis[x][y]!=1) return; ans++; queue<point> q; point a; a.x=x; a.y=y; q.push(a); point now,next; now.x=x; now.y=y; while(!q.empty()) { now=q.front(); for(int i=0;i<8;i++) { next.x=now.x+dx[i]; next.y=now.y+dy[i]; if(next.x<0||next.x>=n) continue; if(next.y<0||next.y>=m) continue; if(vis[next.x][next.y]!=1) continue; vis[next.x][next.y]=0; q.push(next); } q.pop(); } } int main() { while(cin>>n>>m) { memset(vis,0,sizeof(vis)); if(n==0&&m==0) break; char a; for(int i=0;i<n;i++) { for(int j=0;j<m;j++) { cin>>a; if(a==‘*‘) vis[i][j]=-1; else vis[i][j]=1; } } ans=0; for(int i=0;i<n;i++) { for(int j=0;j<m;j++) { if(vis[i][j]==1) bfs(i,j); } } cout<<ans<<endl; } return 0; }
标签:des style blog ar io color os sp for
原文地址:http://www.cnblogs.com/qscqesze/p/4172633.html