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 ...
随机推荐
- IOS Application Security Testing Cheat Sheet
IOS Application Security Testing Cheat Sheet [hide] 1 DRAFT CHEAT SHEET - WORK IN PROGRESS 2 Int ...
- asp.net添加验证码
1.新建一个aspx页面生成验证码图像 using System; using System.Data; using System.Configuration; using System.Collec ...
- Android界面布局基本属性
在 android 中我们常用的布局方式有这么几种:1.LinearLayout ( 线性布局 ) :(里面只可以有一个控件,并且不能设计这个控件的位置,控件会放到左上角) ...
- 解决删除域用户Exception from HRESULT: 0x80072030
解决删除域用户异常问题. System.DirectoryServices.DirectoryServicesCOMException was unhandled Message=在服务器上没有这样 ...
- Android开发环境搭建相关文章列表(转载)
Android开发虽然有所了解,但是一直没有搭建开发环境去学习,Android的更新速度比较快了,Android1.0是2008年发布的,截止到目前为止Android已经更新Android5.0.1, ...
- Java 停止一个 Thread
boolean flag=true; public void run(){ while(flag){ ... ...
- [0x00 用Python讲解数据结构与算法] 概览
自从工作后就没什么时间更新博客了,最近抽空学了点Python,觉得Python真的是很强大呀.想来在大学中没有学好数据结构和算法,自己的意志力一直不够坚定,这次想好好看一本书,认真把基本的数据结构和算 ...
- java中String byte HexString的转换
原文:http://blog.sina.com.cn/s/blog_62e9ec530101ebv6.html HexString——>byte public static byte[] hex ...
- 红黑树(三)之 Linux内核中红黑树的经典实现
概要 前面分别介绍了红黑树的理论知识 以及 通过C语言实现了红黑树.本章继续会红黑树进行介绍,下面将Linux 内核中的红黑树单独移植出来进行测试验证.若读者对红黑树的理论知识不熟悉,建立先学习红黑树 ...
- LoRaWAN协议(一)--架构解析
LoRaWAN 分层 总体架构一共分为4部分: LoRaWAN从底层到最后用户拿到数据的通讯过程通讯大致可分为三段: MOTE <---> GW (MAC层) GW <---> ...