站外题救助
  • 板块学术版
  • 楼主_sylveon
  • 当前回复0
  • 已保存回复0
  • 发布时间2024/7/23 20:46
  • 上次更新2024/7/23 20:48:48
查看原帖
站外题救助
1368803
_sylveon楼主2024/7/23 20:46

一本通的题:1250:The Castle

#include<bits/stdc++.h>
using namespace std;
int a[55][55][5],f[55][55],maxn=-1;
int xy[5][3]={{0,-1},{-1,0},{0,1},{1,0}};
int n,m,cnt;
struct t{
	int x,y;
};
queue<t>q;
void bfs(int x,int y)
{
	int ans=1;
	q.push({x,y});
	while(!q.empty())
	{
		t z=q.front();
		q.pop();
		for(int i=0;i<4;i++)
		{
			int nx=z.x+xy[i][0],ny=z.y+xy[i][1];
			if(nx<=n&&nx>=0&&ny<=m&&nx>=0&&a[z.x][z.y][i]==0&&f[nx][ny]==0)
			{
				ans++;
				f[nx][ny]=1;
				q.push({nx,ny});
			}
		}
	}
	maxn=max(maxn,ans);
	cnt++;
}
int main()
{
	cin>>n>>m;
	for(int i=1;i<=n;i++)
	{
		for(int j=1,x;j<=m;j++)
		{
			cin>>x;
			if(x&1)a[i][j][0]=1;
			if(x&2)a[i][j][1]=1;
			if(x&4)a[i][j][2]=1;
			if(x&8)a[i][j][3]=1;
		}
	}
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=m;j++)
		{
			if(f[i][j]==0)
			{
				bfs(i,j);
			}
		}
	}
	cout<<cnt<<"\n"<<maxn;
	return 0;
}

一道简单的BFS。 就说输出时maxn直接输出是20分,maxn-1是80分

2024/7/23 20:46
加载中...