bzoj1751 [Usaco2005 qua]Lake Counting
来源:互联网 发布:js设置边框颜色 编辑:程序博客网 时间:2024/06/05 11:43
bfs找出联通块个数就好了
#include<cstdio>#include<cstring>#include<iostream>#include<algorithm>#define fo(i,a,b) for(int i=a;i<=b;i++)#define fd(i,a,b) for(int i=a;i>=b;i--)using namespace std;const int N=105;int n,m,ans;const int dx[8]={-1,-1,-1,1,1,1,0,0};const int dy[8]={-1,0,1,-1,0,1,1,-1};char s[N][N];struct node{ int x,y;}q[N*N];bool vis[N][N];inline void bfs(int x,int y){ vis[x][y]=1; int t=0,w=1; q[1].x=x; q[1].y=y; while (t<w) { t++; fo(k,0,7) { int x1=q[t].x+dx[k]; int y1=q[t].y+dy[k]; if (x1>=1&&x1<=n&&y1>=1&&y1<=m&&!vis[x1][y1]&&s[x1][y1]=='W') { vis[x1][y1]=1; q[++w].x=x1; q[w].y=y1; } } }}int main(){ scanf("%d%d",&n,&m); fo(i,1,n) { scanf("%s",s[i]+1); } fo(i,1,n) fo(j,1,m) if (s[i][j]=='W'&&!vis[i][j]) { bfs(i,j); ans++; } printf("%d\n",ans);}
阅读全文
0 0
- bzoj1751 [Usaco2005 qua]Lake Counting
- bzoj1751 [Usaco2005 qua]Lake Counting
- [bzoj1751][Usaco2005 qua]Lake Counting
- 1751: [Usaco2005 qua]Lake Counting (搜索)
- bzoj 1751 [Usaco2005 qua]Lake Counting
- bzoj1754 [Usaco2005 qua]Bull Math
- bzoj1755 [Usaco2005 qua]Bank Interest
- 1755: [Usaco2005 qua]Bank Interest
- bzoj1750 [Usaco2005 qua]Apple Catching
- bzoj1755 [Usaco2005 qua]Bank Interest
- bzoj1754: [Usaco2005 qua]Bull Math
- bzoj1755 [Usaco2005 qua]Bank Interest
- bzoj1754 [Usaco2005 qua]Bull Math
- Lake Counting
- Lake Counting
- Lake Counting
- Lake Counting
- Lake Counting
- 计算机图形学-基于OpenGL的直线段的裁剪算法
- Deep Learning(深度学习)学习笔记整理系列之(六)
- Vue--- 子 --> 父 组件传递参数
- 宏与递归
- jQuery插件中为什么要return this.each?
- bzoj1751 [Usaco2005 qua]Lake Counting
- Deep Learning(深度学习)学习笔记整理系列之(七)
- 操作系统之进程同步
- Deep Learning(深度学习)学习笔记整理系列之(八)
- windows环境使用composer安装YII2.0
- tensorflow53 《面向机器智能的TensorFlow实战》笔记-05-01 卷积基础
- fl2440串口编程
- Java Web----实训项目第一阶段
- 创建位图索引