hdu_2952 Counting Sheep
来源:互联网 发布:贵阳 云计算 编辑:程序博客网 时间:2024/06/07 02:08
原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=2952
分析:数一数看有多少群羊(上下左右有连着的是一群羊),用深搜,把连着的羊变成‘.’,看深搜了几次,就有多少群羊。
我的代码:
#include<stdio.h>int n,m;char map[110][110];int x[]={0,0,1,-1};int y[]={1,-1,0,0};void DFS(int sx,int sy){ map[sx][sy]='.'; for(int i=0;i<4;i++) { int nx=sx+x[i]; int ny=sy+y[i]; if(nx<n&&nx>=0&&ny<m&&ny>=0&&map[nx][ny]=='#') { DFS( nx, ny); } }}int main(){ int i,t; scanf("%d",&t); while(t--) { int ans=0; scanf("%d%d",&n,&m); for(i=0;i<n;i++) scanf("%s",map[i]); for(i=0;i<n;i++) { for(int j=0;j<m;j++) { if(map[i][j]=='#') { DFS(i,j); ans++; } } } printf("%d\n",ans); } return 0;}
分析:突然发现原来有的搜索没有那么难-,-。
- hdu_2952 Counting Sheep
- HDU_2952 Counting Sheep( 深搜)
- Counting Sheep
- Counting Sheep
- HDU2952 ( Counting Sheep )
- HDU 2952 Counting Sheep
- hdu 2952 Counting Sheep
- HDU2952:Counting Sheep(DFS)
- HDU2952:Counting Sheep(BFS)
- HDU2952 Counting Sheep
- hdu2952(DFS Counting Sheep )
- hdu-2952-Counting Sheep
- hdu 2952 Counting Sheep
- hdu 2952Counting Sheep
- HDU2952:Counting Sheep(DFS)
- HDU2952:Counting Sheep(BFS)
- HDU 2952 Counting Sheep
- hdu 2952 Counting Sheep
- html5 游戏
- 字节数
- C# Mail邮件程序
- 数字签名与数字证书
- 单例模式的最佳实现
- hdu_2952 Counting Sheep
- Nodejs 项目创建
- C#stream学习
- Python中__del__如何使用
- gd2库中有关imagejpeg问题
- top5-----asynch descriptor resize
- Velocity和FreeMarker模版技术
- poj1836 Alignment
- openoffice 安装 linux and windows