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 ...
随机推荐
- JAVA IO NIO
http://www.cnblogs.com/handsome1013/p/4882862.html http://www.cnblogs.com/dolphin0520/ http://www.cn ...
- JQM[jquery mobile] 实战经验汇总
动态装载的子页面(data-role=”page”),完全不用page div之外的tag,也不会起作用.子页面的javascript脚本必须写在page的</div>之前. 切换按钮(a ...
- 使用jQuery开发iOS风格的页面导航菜单
在线演示1 本地下载 申请达人,去除赞助商链接 iOS风格的操作系统和导航方式现在越来越流行,在今天的jQuery教程中,我们将介绍如何生成一个iphone风格的菜单导航. HTML代码 我们 ...
- 转载好文:如何进行基于情境数据的个性化EDM数据营销
根据Adobe和DMA(Direct Marketing Association)的<实时营销洞察报告> (Real-Time Marketing Insights Study),77%的 ...
- 解决Eclipse报errors running builder ‘javascript validator’ on project
导入jquery的js到项目中,Eclipse每次检测到功能代码变化(保存动作触发)就报错: errors running builder ‘javascript validator’ on proj ...
- SSH: 本地.ssh目录下的公钥文件最好删掉
这次ssh amazon ec2的instance,在家里电脑登录OK,到了公司电脑登录失败(只支持公钥机制).私钥已经拷贝到公司的ubuntu上了,奇怪. 后来发现是.ssh目录下存在一些公钥文件导 ...
- Linux高级编程--08.线程概述
线程 有的时候,我们需要在一个基础中同时运行多个控制流程.例如:一个图形界面的下载软件,在处理下载任务的同时,还必须响应界面的对任务的停止,删除等控制操作.这个时候就需要用到线程来实现并发操作. 和信 ...
- c#关于委托和事件(二)(介绍的很详细)
using System;using System.Collections.Generic;using System.Text; namespace Delegate { // 热水器 p ...
- Struts2的基本流程的详细介绍
Struts2基本流程 概述: Struts2框架由三部分构成:核心控制器.业务控制器和用户实现的业务逻辑组件.在这三部分中,struts2框架提供了核心控制器StrutsPrepareAndExec ...
- 使用saripaar对android输入控件进行快速验证
saripaar是个android的第三方快速校验,使用注解快速添加验证规则. public class LoginActivity extends Activity implements Valid ...