一只P1451的0分代码求调
rt
主诉:
不知如何调
全WA
诉求:
在源代码上改是最好啦!
回复请@楼主
#include<bits/stdc++.h>
using namespace std;
//#define debug
int n,m,ans;
bool z[105][105];
int dx[4]={-1,0,0,1};
int dy[4]={0,-1,1,0};
queue<int> qx,qy;
bool check(int xx,int yy)
{
if(xx<1 || xx>n || yy<1 || yy>n)
return 0;
if(!z[xx][yy])
return 0;
return 1;
}
void bfs(int sx,int sy)
{
qx.push(sx);
qy.push(sy);
while(!qx.empty())
{
int qxh=qx.front(),qyh=qy.front();
qx.pop();
qy.pop();
for(int i=0;i<4;i++)
{
int xx=qxh+dx[i],yy=qyh+dy[i];
if(!check(xx,yy))
continue;
z[xx][yy]=0;
qx.push(xx);
qy.push(yy);
}
}
}
int main()
{
memset(z,-1,sizeof(z));
scanf("%d %d",&n,&m);
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++)
scanf("%1d",&z[i][j]);
#ifdef debug
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
printf("%d",z[i][j]);
printf("\n");
}
#endif
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++)
{
ans++;
bfs(i,j);
}
printf("%d",ans);
return 0;
}