本题来自: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. swift 枚举类型

    1:swift的枚举类型是一系列的值,不同于c语言中枚举类型是整数类型.每个枚举定义了个新的类型 2:switch类型匹配 2.1枚举类型和switch单个匹配 enum PlatType{ case ...

  2. ML的灌水现象

    (http://demonstrate.ycool.com/post.3137870.html) 看了几天 paper 和书,发现自己果然就是 zt好多东西就是不懂,那些人做的真快,我才建立起一种大致 ...

  3. php 类文件加载 Autoloader

    做习惯了编译语言,转到php 使用 php的面向对象开发时候遇见一个挺别扭的问题.在Php中引入对象 后 在调用过程中还需要将对象所在的php文件 require 到当前php文件 目前代码结构 in ...

  4. POJ 2887 Big String(块状链表)

    题目大意 给一个字符串,长度不超过 106,有两种操作: 1. 在第 i 个字符的前面添加一个字符 ch 2. 查询第 k 个位置是什么字符 操作的总数不超过 2000 做法分析 好多不同的做法都可以 ...

  5. ionic介绍

    ionic介绍 Ionic是一个前端的框架,帮助开发者使用HTML5, CSS3和JavaScript做出原生应用. The beautiful, open source front-end fram ...

  6. c/c++:重载 覆盖 隐藏 overload override overwrite

    http://www.cnblogs.com/qlee/archive/2011/07/04/2097055.html 成员函数的重载.覆盖与隐藏成员函数的重载.覆盖(override)与隐藏很容易混 ...

  7. 让我们一起Go(十三)

    前言: 上篇,我们了解了Go语言接口的一些知识,在这篇中,我们将继续聊聊接口这东西. Go语言空接口 Go语言中定义一个空接口,也就是没有任何函数需要实现的接口就是一个空接口,作为一个空接口,因为对象 ...

  8. AssetBundle系列——游戏资源打包(二)

    本篇接着上一篇.上篇中说到的4步的代码分别如下所示: (1)将资源打包成assetbundle,并放到自定目录下 using UnityEditor; using UnityEngine; using ...

  9. 【Head-First设计模式】C#版-学习笔记-开篇及文章目录

    原文地址:[Head-First设计模式]C#版-学习笔记-开篇及文章目录 最近一年断断续续的在看技术书,但是回想看的内容,就忘了书上讲的是什么东西了,为了记住那些看过的东西,最好的办法就是敲代码验证 ...

  10. 【转载】取消Debian系统自动锁屏

    Linux的自动锁屏功能,会在你离开屏幕的两分钟,甚至更短的时候内,将屏幕锁住,需要输入密码才能进入Linux系统. 可按下图设置,关掉Linux自动锁屏功能 System-->Preferen ...