救命!!!!!!!!!!
  • 板块P1162 填涂颜色
  • 楼主Jeeff
  • 当前回复2
  • 已保存回复2
  • 发布时间2024/8/12 13:01
  • 上次更新2024/8/12 14:29:07
查看原帖
救命!!!!!!!!!!
986836
Jeeff楼主2024/8/12 13:01
#include<bits/stdc++.h>
using namespace std;

int a,l[1000][1000],h[1000][1000],ci;

int is1(int x,int y)
{
	
	
	if(h[x][y]==-1)
		return 0;
	else if(h[x][y]==1)
		return 1;
	else if(l[x][y])
		return 1;
	else if(x<1 or y<1 or x>a or y>a)
		return 0;
	else
	{
		bool s=1;
		h[x][y]=1;
		if(!h[x][y-1])
			s&=is1(x,y-1);
		if(!h[x][y+1])
			s&=is1(x,y+1);
		if(!h[x-1][y])
			s&=is1(x-1,y);
		if(!h[x+1][y])
			s&=is1(x+1,y);
		if(s==0 or (l[x+1][y]==0 or h[x+1][y]==-1 and l[x][y+1]==0 or h[x][y+1]==-1 and l[x-1][y]==0 or h[x-1][y]==-1 and l[x][y-1]==0 or h[x][y-1]==-1 ))
			h[x][y]=-1;
			
		for(int i=1;i<=a;i++)
    	{
 			for(int j=1;j<=a;j++)
    		{
				if(h[i][j]==1)
					l[i][j]=2;
				if(h[i][j]==-1)
					l[i][j]=0;
			}
		}
		//cout<<"h:"<<endl;
		//for(int i=1;i<=a;i++)
    	//{
 		//	for(int j=1;j<=a;j++)
    	//	{
		//		cout<<h[i][j]<<" ";
		//	}
		//	cout<<endl;
		//}
		
			
		return s;
	}
}



int main()
{
    cin>>a;
    for(int i=1;i<=a;i++)
       	for(int j=1;j<=a;j++)
       		cin>>l[i][j];
		
    for(int i=1;i<=a;i++)
    	for(int j=1;j<=a;j++)
    		is1(i,j);

	for(int i=1;i<=a;i++)
    {
    	for(int j=1;j<=a;j++)
    		cout<<l[i][j]<<" ";
		cout<<endl;
	}
} 

















2024/8/12 13:01
加载中...