两个都是一类,bfs灌输题就是求有几个二维的联通块,当然dfs和并查集也可以完成
1.分子团,就是对于!0的地方进行灌水
2.Programming Robots,每个不是#的地方进行灌水,然后统计每个联通块里面有几个R
inline void bfs(int x,int y)
{
ans=0;
node st;st.x=x;st.y=y;
vis[st.x][st.y]=1;
q.push(st);
while(!q.empty())
{
node k=q.front();q.pop();
if(a[k.x][k.y]=='R')ans++;
for(int i=0;i<4;i++)
{
int xx=k.x+dx[i];
int yy=k.y+dy[i];
if(!vis[xx][yy]&&a[xx][yy]!='#'&&xx>=1&&xx<=n&&yy>=1&&yy<=m)
{
vis[xx][yy]=1;
node ne;ne.x=xx;ne.y=yy;ne.tep=k.tep+1;
q.push(ne);
}
}
}
tot=max(tot,ans);
}
inline void bfs(int x,int y)
{
ans++;
node st;st.x=x;st.y=y;
vis[st.x][st.y]=1;
q.push(st);
while(!q.empty())
{
node k=q.front();q.pop();
for(int i=0;i<4;i++)
{
int xx=k.x+dx[i];
int yy=k.y+dy[i];
if(!vis[xx][yy]&&a[xx][yy]!='0'&&xx>=1&&xx<=n&&yy>=1&&yy<=m)
{
vis[xx][yy]=1;
node ne;ne.x=xx;ne.y=yy;ne.tep=k.tep+1;
q.push(ne);
}
}
}
}