hdu 2952 Counting Sheep
本题来自: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的更多相关文章
- HDU 2952 Counting Sheep(DFS)
题目链接 Problem Description A while ago I had trouble sleeping. I used to lie awake, staring at the cei ...
- ACM HDU-2952 Counting Sheep
Counting Sheep Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) T ...
- hdu 5862 Counting Intersections
传送门:hdu 5862 Counting Intersections 题意:对于平行于坐标轴的n条线段,求两两相交的线段对有多少个,包括十,T型 官方题解:由于数据限制,只有竖向与横向的线段才会产生 ...
- 【DFS深搜初步】HDOJ-2952 Counting Sheep、NYOJ-27 水池数目
[题目链接:HDOJ-2952] Counting Sheep Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 ...
- Counting sheep...
Counting sheep... Description: Consider an array of sheep where some sheep may be missing from their ...
- HDU-2952 Counting Sheep (DFS)
Counting Sheep Time Limit : 2000/1000ms (Java/Other) Memory Limit : 32768/32768K (Java/Other) Tota ...
- HDU 3046 Pleasant sheep and big big wolf(最小割)
HDU 3046 Pleasant sheep and big big wolf 题目链接 题意:一个n * m平面上,1是羊.2是狼,问最少要多少围墙才干把狼所有围住,每有到达羊的路径 思路:有羊和 ...
- HDU 5862 Counting Intersections(离散化+树状数组)
HDU 5862 Counting Intersections(离散化+树状数组) 题目链接http://acm.split.hdu.edu.cn/showproblem.php?pid=5862 D ...
- HDU2952:Counting Sheep(DFS)
Counting Sheep Time Limit : 2000/1000ms (Java/Other) Memory Limit : 32768/32768K (Java/Other) Tota ...
随机推荐
- 使用PowerDesigner导出Word/HTML的一些配置
目标:根据物理视图导出代码和列清单(包括字段.类型.注释).由于默认导出的要素太多,大多不是自己想要的,这里简单说下导出目标的一些配置,留下来备用. 其中,Title中的图和Table表格中的代码预览 ...
- 何为.Net Remoting【转】
借助基维百科给它的定义如下: NET Remoting 是微软 .NET Framework 中的一种网络通讯技术,与 XML Web Service 不同的是,它可以使用 SOAP 以外的协定来通讯 ...
- Oracle数据库入门——常用的数据字典
一.oracle数据字典主要由以下几种视图构成:1.user视图以user_为前缀,用来记录用户对象的信息 2.all视图以all_为前缀,用来记录用户对象的信息及被授权访问的对象信息 3.dba视图 ...
- delphi7的新生,参与分布式应用开发,调用RESTful API,Json的应用
前言: 1.公司delphi7开发的传统软件还活得好好的,但是大家都知道delphi早已经日落西山了,现在成了后进.追随者.细细算了已经6.7不用了.新的delphixe7呢,没有时间成本去适应和研究 ...
- 一种高效的 vector 四则运算处理方法
实现 vector 的四则运算 这里假设 vector 的运算定义为对操作数 vector 中相同位置的元素进行运算,最后得到一个新的 vector.具体来说就是,假如 vector<int&g ...
- ruby 中文字符to_json后乱码(unicode)
今天遇到一个中文to_json问题 text = "第1章 青豆 不要被外表骗了" text.to_json => "\"\\u7b2c1\\u7ae0 ...
- Android 2.1 和 Android 4.4 工程目录超详细对比及详解
在搭建Android开发环境及简单地建立一个HelloWorld项目后,本篇将通过HelloWorld项目来介绍Android项目的目录结构.本文的主要主题如下: 1.1.HelloWorld项目的目 ...
- [转]查看手机已经记住的WIFI密码
有时用过wifi后记住密码了,但再想知道wifi密码是多少,怎么办呢.下面的方法为你解决这样的问题. 1.手机必须取得root权限. 2.用RE管理器或es文件浏览器进入data/misc/wifi, ...
- 短日期比较 js
function compareDate(startDate, endDate) { var arr = startDate.split("-"); var starttime = ...
- mysql 行转列
SELECTREPLACE(GROUP_CONCAT(IF(ItemID=1101,ItemValue,"")),',',"") AS 'Item1101',R ...