HDU 2952 Counting Sheep(bfs)
来源:互联网 发布:java并发编程好的书籍 编辑:程序博客网 时间:2024/06/08 02:45
题目:http://acm.hdu.edu.cn/showproblem.php?pid=2952
代码:
#include<stdio.h>#include<string.h>#include<queue>using namespace std;char maps[105][105];int fx[4]={1,0,-1,0};int fy[4]={0,-1,0,1};int dis[105][105];int a,b;struct node{ int x,y;}point[105];bool judge(int x,int y){ if(x>=0&&x<a&&y>=0&&y<b&&maps[x][y]=='#') return true; return false;}int bfs(int xx,int yy){ queue<node>q; node star,en; star.x=xx; star.y=yy; q.push(star); dis[xx][yy]=1; while(!q.empty()) { en=q.front(); q.pop(); for(int i=0;i<4;i++) { int dx,dy; dx=en.x+fx[i]; dy=en.y+fy[i]; if(judge(dx,dy)&&dis[dx][dy]==0) { star.x=dx; star.y=dy; q.push(star); dis[dx][dy]=dis[en.x][en.y]+1; } } } return 0;}int main(){ int t; scanf("%d",&t); while(t--) { scanf("%d%d",&a,&b); for(int i=0;i<a;i++) { scanf("%s",maps[i]); } int ans=0; memset(dis,0,sizeof(dis)); for(int i=0;i<a;i++) { for(int j=0;j<b;j++) { if(maps[i][j]=='#'&&dis[i][j]==0) { bfs(i,j); ans++; } } } printf("%d\n",ans); }}
0 0
- HDU 2952 Counting Sheep(bfs)
- HDU 2952 Counting Sheep ( DFS + BFS )
- HDU 2952 Counting Sheep
- hdu 2952 Counting Sheep
- hdu-2952-Counting Sheep
- hdu 2952 Counting Sheep
- hdu 2952Counting Sheep
- HDU 2952 Counting Sheep
- hdu 2952 Counting Sheep
- HDU 2952 Counting Sheep
- hdu 2952 Counting Sheep
- hdu 2952 Counting Sheep
- HDU 2952 Counting Sheep
- hdu 2952 Counting Sheep
- hdu 2952 Counting Sheep
- hdu 2952 Counting Sheep
- hdu 2952 Counting Sheep
- HDU 2952 Counting Sheep
- 刷题、OJ 1912 亲和数
- 总结五---一步一步,脚踏实地
- 238. Product of Array Except Self LeetCode
- Codeforces Round #287 (Div. 2) E. Breaking Good(最短路、dp)
- Tomcat分析--Connector
- HDU 2952 Counting Sheep(bfs)
- Hadoop MapReduce之MapOutputBuffer分析
- java,dex 文件编译反编译
- iOS中 蓝牙2.0详解ios蓝牙设备详解 韩俊强的博客
- 【VB6】VB6类库项目中的MTSTransactionMode
- Spark分区器HashPartitioner和RangePartitioner代码详解
- iOS中 加强日志输出 开发技术总结
- 《大话设计模式》导图总结
- 石子合并