sjtu oj 1003.二哥养细菌
2014-02-21 22:21
337 查看
#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; }
相关文章推荐
- 网络编程socket
- AMDBarUtility Update Ditection Page
- android 面试
- windows与linux网络设置(host-only)
- bash参考手册之五(shell变量)
- 产品运营小议
- 1127笔记
- sjtu oj 1002.二哥种花生
- [转载]Winform等待窗口的实现(附源代码)
- Nginx常用命令
- 计算机启动过程
- 浅谈iOS与社交化网络
- Java反射机制 笔记
- Java Simple Introduce
- android颜色对应的xml配置值,颜色表
- sth about Hadoop
- java+mysql中文乱码问题
- 发布应用程序
- lua工具库penlight--02表和数组
- STL -- map--vector--排序