HDUOJ----2952Counting Sheep
Counting Sheep
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1782 Accepted Submission(s): 1170
Creative as I am, that wasn't going to stop me. I sat down and wrote a computer program that made a grid of characters, where # represents a sheep, while . is grass (or whatever you like, just not sheep). To make the counting a little more interesting, I also decided I wanted to count flocks of sheep instead of single sheep. Two sheep are in the same flock if they share a common side (up, down, right or left). Also, if sheep A is in the same flock as sheep B, and sheep B is in the same flock as sheep C, then sheeps A and C are in the same flock.
Now, I've got a new problem. Though counting these sheep actually helps me fall asleep, I find that it is extremely boring. To solve this, I've decided I need another computer program that does the counting for me. Then I'll be able to just start both these programs before I go to bed, and I'll sleep tight until the morning without any disturbances. I need you to write this program for me.
Each test case begins with a line containing two numbers, H and W, the height and width of the sheep grid. Then follows H lines, each containing W characters (either # or .), describing that part of the grid.
Notes and Constraints
0 < T <= 100
0 < H,W <= 100
//简单的搜索
#include<cstdio>
#include<queue>
#include<iostream>
using namespace std;
const int maxn=;
char map[maxn][maxn];
typedef struct
{
int x,y;
}po;
int dir[][]={{,}, {-,}, {,} , {,-} } ;
int main()
{
int n,m,t,i,j,k,ans;
queue<po>tem;
scanf("%d",&t);
while(t--)
{
ans=;
scanf("%d%d",&n,&m);
for(i=;i<n;i++)
scanf("%s",map[i]);
for(i=;i<n;i++)
{
for(j=;j<m;j++)
{
if(map[i][j]=='#')
{
ans++;
map[i][j]='.';
po st={i,j};
tem.push( st );
while(!tem.empty())
{
po en=tem.front();
tem.pop();
for(k=;k<;k++)
{
if(map[en.x+dir[k][]][en.y+dir[k][]]=='#')
{
map[en.x+dir[k][]][en.y+dir[k][]]='.';
po sa={en.x+dir[k][],en.y+dir[k][]};
tem.push(sa);
}
}
}
}
}
}
printf("%d\n",ans);
}
return ;
}
HDUOJ----2952Counting Sheep的更多相关文章
- hduoj 1455 && uva 243 E - Sticks
http://acm.hdu.edu.cn/showproblem.php?pid=1455 http://uva.onlinejudge.org/index.php?option=com_onlin ...
- 2001. Counting Sheep
After a long night of coding, Charles Pearson Peterson is having trouble sleeping. This is not onl ...
- hduoj 4712 Hamming Distance 2013 ACM/ICPC Asia Regional Online —— Warmup
http://acm.hdu.edu.cn/showproblem.php?pid=4712 Hamming Distance Time Limit: 6000/3000 MS (Java/Other ...
- hduoj 4706 Herding 2013 ACM/ICPC Asia Regional Online —— Warmup
hduoj 4706 Children's Day 2013 ACM/ICPC Asia Regional Online —— Warmup Herding Time Limit: 2000/1000 ...
- hdu 3046 Pleasant sheep and big big wolf 最小割
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3046 In ZJNU, there is a well-known prairie. And it a ...
- 【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 ...
- Funny Sheep(思维)
Problem 1606 - Funny Sheep Time Limit: 1000MS Memory Limit: 65536KB Total Submit: 612 Accepted ...
- hdu2952Counting Sheep
Problem Description A while ago I had trouble sleeping. I used to lie awake, staring at the ceiling, ...
随机推荐
- MIR Flickr 1M 图像数据集(点击即可下载)
Index of /mirflickr/mirflickr1m Name Last modified Size Description Parent Directory - exif.zip ...
- Informatica 常用组件Lookup之四 查找组件
在映射中配置查找转换时,请定义以下组件: 查找源 端口 属性 条件 元数据扩展 查找源 您可以使用平面文件或关系表作为查找源.创建查找转换时,您可以从以下位置导入查找源: 资料库中的任 ...
- Divide Two Integers leetcode java
题目: Divide two integers without using multiplication, division and mod operator. 题解: 这道题我自己没想出来...乘除 ...
- VB.NET与C# 语法区别展示
在学习VB.NET后发现,VB.NET与C#的语法主要的不同在两个部分,这两部分搞通了,那就游刃有余,迎刃而解了.现将其对比总结如下: 一.实体部分 (与VB相比,在C#和VB.NET中,实体的使用很 ...
- MongoDB学习笔记(四)--索引 && 性能优化
索引 基础索引 ...
- .NET/Mysql-petatoco连接mysql数据库
安装mysql数据库 用nugget添加.net连接mysql数据库的组件
- (算法)位图BitMap
题目: 给定一数组,大小为M,数组中的数字范围为1-N,如果某带宽有限,无法传输该大小的数组,该怎么办? 思路: 通过位图BitMap来压缩数组,将数组中每个数字在bit位上标志,这样就可以将数组大小 ...
- Opencv2.4.9安装和在visualstudio 2013中配置
Opencv2.4.9安装和在visualstudio 2013中配置 下载opencv和在windows下安装: 最新版本号的opencv是2014.4.25的opencv2.4.9,这里选择当前最 ...
- Win7没有防火墙:0x80070422
在"MSDN我告诉你"下载的官方原版Window7 64位,安装后防火墙是这样的: 点击"使用推荐设置",报错:0x80070422,估计是因为使用PE中的工具 ...
- Jacoco覆盖率工具使用
Jacoco介绍 Jacoco是一个开源的覆盖率工具.Jacoco可以嵌入到Ant .Maven中,并提供了EclEmma Eclipse插件,也可以使用JavaAgent技术监控Java程序.很多第 ...