| ||||||||||
| 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 | |||||||||
用 bool16ms,用char 0ms#include <iostream>
#include <cstdio>
#include <cstdlib>
using namespace std;
char map[102][102];
void v(int x,int y,int n)
{
if(n>100||!map[x][y])return;
map[x][y]=0;n++;
v(x-1,y-1,n);v(x,y-1,n);v(x+1,y-1,n);
v(x-1, y ,n); v(x+1, y ,n);
v(x-1,y+1,n);v(x,y+1,n);v(x+1,y+1,n);
return;
}
bool solve()
{
int m,n,i,j,ans=0;
scanf("%d%d",&m,&n);
if(!(m+n))return 0;
char t;
for(i=1;i<=m;i++)
{
while(getchar()!='\n');
for(j=1;j<=n;j++)
{
t=getchar();
if(t=='@')map[i][j]=1;
else map[i][j]=0;
}
map[i][j]=0;
}
for(j=1;j<=n;j++) map[i][j]=0;
for(i=1;i<=m;i++)
for(j=1;j<=n;j++)
if(map[i][j]){ans++;v(i,j,1);}
printf("%d\n",ans);
return 1;
}
int main()
{
while(solve());
return 0;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator