40分求助!萌新求助
查看原帖
40分求助!萌新求助
971024
Jerry_zpl楼主2024/4/15 18:00

我才学到连通块

#include<bits/stdc++.h>
using namespace std;
int a[505][505],k[505][505];
int n,m;
int main()
{
	cin.tie(0);
	cout.tie(0);
	cin>>n>>m;
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=m;j++)
		{
			cin>>k[i][j];
		}
	}
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=m;j++)
		{
			for(int x=1;x<=n;x++)
			{
				for(int y=1;y<=m;y++)
				{
					if(k[i][j]==k[x][y])
					{
						a[i][j]=max(a[i][j],(i-x)*(i-x)+(j-y)*(j-y));
					}
				}
			}
		}
	}
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=m;j++)
		{
			cout<<a[i][j]<<" ";
		}
		cout<<endl;
	}
	return 0;
}
2024/4/15 18:00
加载中...