本题来自:http://acm.hdu.edu.cn/showproblem.php?pid=2952

题意:上下左右4个方向为一群。搜索有几群羊

 #include <stdio.h>
#include<string.h>
char graph[][];
int w,h;
int tab[][]={,,,,-,,,-}; void dfs(int x,int y)
{
graph[x][y]='.';
for(int i=;i<;i++)
{
int xx=x+tab[i][];
int yy=y+tab[i][];
if(<=xx&&xx<h&&<=yy&&yy<w&&graph[xx][yy]=='#')
dfs(xx,yy);
}
} void solve()
{
int ans=;
for(int i=;i<h;i++)
for(int j=;j<w;j++)
if(graph[i][j]=='#')
{
dfs(i,j);
ans++;
}
printf("%d\n",ans);
}
int main()
{
int T;
scanf("%d",&T);
while(T--)
{
memset(graph,'\0',sizeof(graph));
scanf("%d%d",&h,&w);
getchar();
// 输入
for(int i=;i<h;i++)
{
for(int j=;j<w;j++)
scanf("%c",&graph[i][j]);
getchar();
}
solve(); // 计算
}
return ;
}

hdu 2952 Counting Sheep的更多相关文章

  1. HDU 2952 Counting Sheep(DFS)

    题目链接 Problem Description A while ago I had trouble sleeping. I used to lie awake, staring at the cei ...

  2. ACM HDU-2952 Counting Sheep

    Counting Sheep Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) T ...

  3. hdu 5862 Counting Intersections

    传送门:hdu 5862 Counting Intersections 题意:对于平行于坐标轴的n条线段,求两两相交的线段对有多少个,包括十,T型 官方题解:由于数据限制,只有竖向与横向的线段才会产生 ...

  4. 【DFS深搜初步】HDOJ-2952 Counting Sheep、NYOJ-27 水池数目

    [题目链接:HDOJ-2952] Counting Sheep Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 ...

  5. Counting sheep...

    Counting sheep... Description: Consider an array of sheep where some sheep may be missing from their ...

  6. HDU-2952 Counting Sheep (DFS)

    Counting Sheep Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 32768/32768K (Java/Other) Tota ...

  7. HDU 3046 Pleasant sheep and big big wolf(最小割)

    HDU 3046 Pleasant sheep and big big wolf 题目链接 题意:一个n * m平面上,1是羊.2是狼,问最少要多少围墙才干把狼所有围住,每有到达羊的路径 思路:有羊和 ...

  8. HDU 5862 Counting Intersections(离散化+树状数组)

    HDU 5862 Counting Intersections(离散化+树状数组) 题目链接http://acm.split.hdu.edu.cn/showproblem.php?pid=5862 D ...

  9. HDU2952:Counting Sheep(DFS)

    Counting Sheep Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 32768/32768K (Java/Other) Tota ...

随机推荐

  1. 数据库同步工具HKROnline SyncNavigator SQL Server互同步MySQL

    需要联系我QQ:786211180 HKROnline SyncNavigator 是一款专业的 SQL Server, MySQL 数据库同步软件.它为您提供一种简单智能的方式完成复杂的数据库数据同 ...

  2. PostgreSQL表空间、模式、表、用户/角色之间的关系

    PostgreSQL表空间.模式.表.用户/角色之间的关系是本文我们主要要介绍的内容,表空间,数据库,模式,表,用户,角色之间的关系到底是怎样的呢?接下来我们就开始介绍这一过程. 实验出角色与用户的关 ...

  3. sencha cmd 更新日志

    http://cdn.sencha.com/cmd/6.2.1.29/release-notes.html

  4. 写出几种IE6 BUG的解决方法

    1.双边距BUG float引起的  使用display:inline 2.3像素问题 使用多个float和注释引起的 使用dislpay:inline -3px   3.超链接hover 点击后失效 ...

  5. DSP中CMD文件

    DSP中CMD文件 (2012-12-26 20:54:17) 转载▼ 标签: 杂谈 分类: DSP FPGA DSP的存储器的地址范围,CMD是主要是根据那个来编的.CMD 它是用来分配rom和ra ...

  6. IEEEtran模版中添加中文:\usepackage{CJKutf8}

    \documentclass[conference]{IEEEtran} \usepackage{cite} \usepackage{graphicx} \usepackage{CJKutf8} \b ...

  7. MyBatis知多少(9)不同类型的数据库

    并非所有的数据库都如此复杂,需要使用昂贵的数据库管理系统以及企业级的硬件.一些数 据库其实非常小,足以运行在一台老式的PC机上.所有的数据库都是不一样的.它们有各自不 同的需求和不同的挑战.iBATI ...

  8. java 时间转换

    public static int timestrtosec(String time) {        if (Strings.isNullOrEmpty(time)) {            r ...

  9. google翻译,翻译当前的网页

    网页翻译为德语(Translate Page To German) <a href="javascript: void(window.open('http://translate.go ...

  10. HTML5探索一(那些新增的标签和属性)

    tml5相比html4,添加了部分语义化的标签和属性,现在我们就从这些标签和属性开始,学习html5吧. 首先,认识下HTML5新的文档类型: <!DOCTYPE html> 那些新标签 ...