好像是个球连通块(从6开始找连通块的大小)的,但是不知道哪错了
过83%
#include<bits/stdc++.h>
using namespace std;
inline int read()
{
int s=0,w=1;
char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}
while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();
return s*w;
}
inline void write(int x)
{
if(x<0) putchar('-'),x=-x;
if(x>9) write(x/10);
putchar(x%10+'0');
}
int n,m,Map[1001][1001],s,t,vis[1001][1001];
int dx[1001]={1,0,-1,0},dy[1001]={0,1,0,-1};
struct node
{
int x,y;
node(int xx,int yy)
{
x=xx;
y=yy;
}
};
queue<node> q;
int ans=1;
inline void bfs(int s,int t)
{
vis[s][t]=1;
q.push(node(s,t));
while(!q.empty())
{
node now=q.front();
q.pop();
int x=now.x,y=now.y;
for(int i=0;i<4;i++)
{
int tx=x+dx[i],ty=y+dy[i];
if(!vis[tx][ty]&&Map[tx][ty]!=2&&tx>=1&&tx<=n&&ty>=1&&ty<=m)
{
vis[tx][ty]=1;
q.push(node(tx,ty));
ans++;
}
}
}
}
int main()
{
n=read();
m=read();
s=1;
t=1;
bool flag=1;
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
{
Map[i][j]=read();
if(Map[i][j]==6)
{
s=i;
t=j;
flag=0;
}
}
}
if(flag)
{
puts("0");
return 0;
}
bfs(s,t);
write(ans);
puts("");
}