68分(求大佬指导……)
查看原帖
68分(求大佬指导……)
1002557
Linda01楼主2024/7/25 09:04

为什么只有68(伤心) 求大佬指导…… 错了第二个测试点和第四个测试点……(wa了的)

#include<bits/stdc++.h>
using namespace std;
int a[36][36],a1[36][36],n;
void bfs3(int h,int l)
{
	//cout<<"ok"<<endl;
	if(a1[h+1][l]==0&&l<n)
	{
		a1[h+1][l]=3;
		bfs3(h+1,l);
	}
	if(a1[h][l+1]==0&&l<n)
	{
		a1[h][l+1]=3;
		bfs3(h,l+1);
	}
	if(a1[h-1][l]==0&&h>0)
	{
		a1[h-1][l]=3;
		bfs3(h-1,l);
	}
	if(a1[h][l-1]==0&&l>0)
	{
		a1[h][l-1]=3;
		bfs3(h,l-1);
	}
	/*	for(int i=0;i<n;i++)
	{
		for(int j=0;j<n;j++)
		{
			cout<<a1[i][j]<<" ";
		}
		cout<<endl;
	}*/
	return;
}
void dfs(int h,int l)
{
	if(h==0||l==0||h==n-1||l==n-1)
	{
		a1[h][l]=3;
		bfs3(h,l);
	}
	
}
/*void bfs2(int h,int l)
{
	//cout<<"ok"<<endl;
	if(a[h][l]==2||a[h][l]==1||a1[h][l]==3)
	{
		return;
	}
	if(a[h][l]==0)
	{
		a[h][l]==2;
	}	
	bfs2(h+1,l);	
	bfs2(h,l+1);
	bfs2(h,l-1);
	bfs2(h-1,l);
	return;
}*/
/*void bfs2(int h,int l)
{
	//cout<<"ok"<<endl;
	if(a[h+1][l]==0&&l<n)
	{
		a[h+1][l]=2;
		bfs2(h+1,l);
	}
	if(a[h][l+1]==0&&l<n)
	{
		a[h][l+1]=2;
		bfs2(h,l+1);
	}
	if(a[h-1][l]==0&&h!=0)
	{
		a[h-1][l]=2;
		bfs2(h-1,l);
	}
	if(a[h][l-1]==0&&l!=0)
	{
		a[h][l-1]=2;
		bfs2(h,l-1);
	}
	/*	for(int i=0;i<n;i++)
	{
		for(int j=0;j<n;j++)
		{
			cout<<a1[i][j]<<" ";
		}
		cout<<endl;
	}
	return;
}*/
int main()
{
	cin>>n;
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<n;j++)
		{
			cin>>a[i][j];
			a1[i][j]=a[i][j];
		}
	}
	/*for(int i=0;i<n;i++)
	{
		for(int j=0;j<n;j++)
		{
			cout<<a1[i][j]<<" ";
		}
		cout<<endl;
	}*/
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<n;j++)
		{
			if(a1[i][j]==0)
			{
				dfs(i,j);
			}
			
		}
	}
	/*for(int i=0;i<n;i++)
	{
		for(int j=0;j<n;j++)
		{
			cout<<a1[i][j]<<" ";
		}
		cout<<endl;
	}*/
	/*for(int i=0;i<n;i++)
	{
		for(int j=0;j<n;j++)
		{
			if(a1[i][j]==0)
			{
				a[i][j]=2;
				bfs2(i,j);
				//cout<<"ok"<<endl;
			}
			
		}
	}*/
	//cout<<endl;
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<n;j++)
		{
			if(a1[i][j]==0)
			{
				cout<<2<<" ";
			}
			else
			{
			    cout<<a[i][j]<<" ";
			}
		}
		cout<<endl;
	}
	/*for(int i=0;i<n;i++)
	{
		for(int j=0;j<n;j++)
		{
			cout<<a1[i][j]<<" ";
		}
		cout<<endl;
	}*/
	return 0;
}

测试点二(输入)

6
0 0 1 1 1 0
1 1 1 0 1 0
1 0 0 0 0 1
1 1 0 1 1 1
0 1 0 1 0 0
0 1 1 1 0 0

(输出)``` 0 0 1 1 1 0 1 1 1 2 1 0 1 2 2 2 2 1 1 1 2 1 1 1 0 1 2 1 0 0 0 1 1 1 0 0

(我的代码输出)```
0 0 1 1 1 0
1 1 1 2 1 0
1 2 2 2 2 1
1 1 2 1 1 1
0 1 2 1 0 0
0 1 1 1 0 0
2024/7/25 09:04
加载中...