一只P1451的0分代码求调
  • 板块学术版
  • 楼主ltm_soviet
  • 当前回复2
  • 已保存回复2
  • 发布时间2024/10/8 19:14
  • 上次更新2024/10/8 21:07:52
查看原帖
一只P1451的0分代码求调
1383031
ltm_soviet楼主2024/10/8 19:14

一只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;
}
2024/10/8 19:14
加载中...