bzoj1751 [Usaco2005 qua]Lake Counting
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);
}
bzoj1751 [Usaco2005 qua]Lake Counting相关推荐
- DFS:深入优先搜索 POJ-2386 Lake Counting
深度优先搜索是从最开始的状态出发,遍历所有可以到达的状态. 因此可以对所有的状态进行操作,或列举出所有的状态. Lake Counting POJ - 2386 Due to recent rains ...
- Lake Counting POJ - 2386
Due to recent rains, water has pooled in various places in Farmer John's field, which is represented ...
- POJ 2386 Lake Counting
链接:http://poj.org/problem?id=2386 Lake Counting Time Limit: 1000MS Memory Limit: 65536K Total Submis ...
- 信息学奥赛一本通(1249:Lake Counting)
1249:Lake Counting 时间限制: 1000 ms 内存限制: 65536 KB 提交数: 9435 通过数: 4902 [题目描述] 题意:有一块N×M的土地, ...
- NUC1158 Lake Counting【DFS】
Lake Counting 时间限制: 1000ms 内存限制: 65536KB 通过次数: 1总提交次数: 1 问题描述 Due to recent rains, water has pooled ...
- bzoj 3385: [Usaco2004 Nov]Lake Counting 数池塘(DFS)
3385: [Usaco2004 Nov]Lake Counting 数池塘 Time Limit: 1 Sec Memory Limit: 128 MB Submit: 78 Solved: 6 ...
- bzoj 1630 2023: [Usaco2005 Nov]Ant Counting 数蚂蚁(有重复元素的组合数)
2023: [Usaco2005 Nov]Ant Counting 数蚂蚁 Time Limit: 4 Sec Memory Limit: 64 MB Submit: 281 Solved: 18 ...
- c++ Lake Counting
Lake Counting(bfs dfs) 题目描述 样例输入 10 12 W . . . . . . . . W W . . W W W . . . . . W W W . . . . W W . ...
- Lake Counting S
Lake Counting S- [P1596 [USACO10OCT]Lake Counting S] 题目分析:刚开始我一直看不懂题目的意思,经过朋友的解释后我忽然发现这就是一个连通块的题目,与染 ...
- poj 2386 Lake Counting
poj 2386 Lake Counting 题目链接:http://poj.org/problem?id=2386 题目大意:数湖. 题目 ...
最新文章
- 第1关:利用栈实现整数的十进制转八进制
- 内存 : DDR2与DDR
- spring 事务 配置 多个
- .Net之代码优先gRPC服务
- 485串口光纤转换器产品介绍
- 前端学习(2791):实现上拉加载更多
- react native ios 上架
- Android 系统(81)---Android permission 动态申请、授权
- 解决FlexPaper分页分段加载问题(转)
- 2020年5月十大热门报告盘点(附下载链接)
- python3实现图片虚化显示轮廓
- MySQL中show profile详解
- 三度盈利,51Talk稳了吗?
- sql 创建学生表 课程表 成绩表
- Open Cascade 多视图-多个3D视图
- 数据泄露的类型以及如何防止它们
- C# LINQ TO SQL
- poj 2228 Naptime(DP的后效性处理)
- 【高级Java开发】类QQ聊天工具的设计与实现(代码已上传)
- 系统接口对接:(2)