sjtu oj 1003.二哥养细菌

#include <iostream>
#include <stdio.h>
#include <queue>
using namespace std;
struct point
{
	int x,y;	
	point(int a,int b){x=a;y=b;}
	point(){};
};
int L,res=0,n0=0,n1=0,temp,c[100][100];
queue<point> q;

bool check(int x,int y)
{
	if(x<0||x>=L||y<0||y>=L)
		return false;
	if(c[x][y]!=0)
		return false;
	return true;
}
void f()
{
	temp=0;
	int x,y;
	while(n1--)
	{
		x=q.front().x;
		y=q.front().y;
		q.pop();
		if(check(x-1,y))
		{
			temp++;
			q.push(point(x-1,y));
			c[x-1][y]=1;
		}
		if(check(x,y-1))
		{
			temp++;
			q.push(point(x,y-1));
			c[x][y-1]=1;
		}
		if(check(x,y+1))
		{
			temp++;
			q.push(point(x,y+1));
			c[x][y+1]=1;
		}
		if(check(x+1,y))
		{
			temp++;
			q.push(point(x+1,y));
			c[x+1][y]=1;
		}
		
	}
	n1=temp;
	n0-=temp;

}
int main()
{
	int i,j;
	scanf("%d",&L);
	for(i=0;i<L;i++)
	{
		for(j=0;j<L;j++)
		{
			scanf("%d",&c[i][j]);
			if(c[i][j]==1)
			{
				q.push(point(i,j));
				n1++;
			}
			if(c[i][j]==0)
				n0++;
		}
	}
	while(n0)
	{
		f();
		res+=1;
	}
	printf("%d\n",res);
	return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值