POJ 2386 Lake Counting
来源:互联网 发布:淘宝贷款入口 编辑:程序博客网 时间:2024/05/02 04:28
/** 题目:Lake Counting** 地址:http://poj.org/problem?id=2386** 题意:求w相连集合的个数**/ #include <iostream>#include <cstring>#include <cstdio>#include <queue>using namespace std; struct node{ int x,y;}s,e; queue <node> q; int d[8][2] = {-1,0, 0,1, 1,1, 1,0, 0,-1 , -1,1, 1,-1, -1,-1}; //搜索到A点时,用来向A点周围的点延生 bool f[110][110]; // 标记char map[110][110];int n,m; bool is_ok(int x, int y) { if(x>=1 && x<=n && y>=1 && y<=m && map[x][y] == 'W') return true; return false;} void bfs(int x,int y){ f[x][y] = true; // 标记此点已经访问过 s.x = x; s.y = y ; q.push(s); // 第一个点入队 while(!q.empty()) { s = q.front(); q.pop(); for(int i=0;i<8;i++) { int xx = s.x + d[i][0]; int yy = s.y + d[i][1]; while(is_ok(xx,yy)) { if(f[xx][yy]==false) { f[xx][yy] = true; e.x = xx; e.y = yy; q.push(e); } xx += d[i][0]; yy += d[i][1]; } } }} int main(){ int i,j; int ans; while(scanf("%d %d",&n,&m)!=EOF) { ans=0; memset(f,false ,sizeof(f)); while(!q.empty()) q.pop(); memset(map,0,sizeof(map)); for(i=1;i<=n;i++) for(j=1;j<=m;j++) scanf(" %c",&map[i][j]); for(i=1;i<=n;i++) { // 从起点开始,遍历所有没有被标记的'W',然后用BFS把与此点相连的点全部标记。 for(j=1;j<=m;j++) if(map[i][j]=='W'&&f[i][j]==false){ bfs(i,j); ans++;} } printf("%d\n",ans); } return 0; }
0 0
- poj 2386 Lake Counting
- poj 2386 Lake Counting
- POJ 2386 Lake Counting
- poj 2386 Lake Counting
- poj 2386 Lake Counting
- poj 2386 Lake Counting
- POJ 2386 Lake Counting
- poj 2386 Lake Counting
- POJ 2386 Lake Counting
- POJ 2386 Lake Counting
- poj 2386 Lake Counting
- POJ 2386 Lake Counting
- POJ 2386 Lake Counting
- POJ-2386-Lake Counting
- POJ 2386 Lake Counting
- poj 2386 Lake Counting
- Poj 2386 Lake Counting
- poj 2386 Lake Counting
- js判断浏览器
- iOS多线程编程之NSThread的使用
- 深入浅出Symfony2 - 结合MongoDB开发LBS应用
- shell脚本学习参考----预
- [总结]FFMPEG视音频编解码零基础学习方法 ---总结的不错
- POJ 2386 Lake Counting
- Qt 不规则窗体 <摘抄>
- 电子政务云
- 宽容的力量
- iOS应用程序生命周期(前后台切换,应用的各种状态)详解
- hdu-1013杭电耍花招,他给了一个长度为一千的数。。。
- 系统学习jQuery.核心知识.局部.jQuery操作.DOM操作.复制节点
- 用AVR单片机来产生正弦波信号
- 虚拟化:LXC, KVM