sjtu oj 1003.二哥养细菌

来源:互联网 发布:通用顶级域名有几个 编辑:程序博客网 时间:2024/05/01 15:47
#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
原创粉丝点击