Description

Bessie is planning her day of munching tender spring grass and is gazing
out upon the pasture which Farmer John has so lovingly partitioned into a
grid with R (1 <= R <= 100) rows and C (1 <= C <= 100) columns. She wishes
to count the number of grass clumps in the pasture. Each grass clump is shown on a map as either a single '#' symbol or perhaps
two '#' symbols side-by-side (but not on a diagonal). Given a map of the
pasture, tell Bessie how many grass clumps there are. By way of example, consider this pasture map where R=5 and C=6: .#....
..#...
..#..#
...##.
.#.... This pasture has a total of 5 clumps: one on the first row, one that spans
the second and third row in column 2, one by itself on the third row, one
that spans columns 4 and 5 in row 4, and one more in row 5.

Input

* Line 1: Two space-separated integers: R and C

* Lines 2..R+1: Line i+1 describes row i of the field with C
characters, each of which is a '#' or a '.'

Output

* Line 1: A single integer that is the number of grass clumps Bessie
can munch
5 6
.#....
..#...
..#..#
...##.
.#....

#include<cstdio>
#include<iostream>
using namespace std;
int x[4]={1,0,-1,0},y[4]={0,1,0,-1};//四个方向
char Map[105][105];
int C,R,ans;
void DFS(int i,int j){
Map[i][j]='.';
for(int t=0;t<4;t++){
int xn=i+x[t];
int yn=j+y[t];
if(xn>=0&&xn<R&&yn>=0&&yn<C&&Map[xn][yn]=='#')
DFS(xn,yn);
}
}
int main ()
{
while(~scanf("%d%d",&R,&C)){
ans=0;
for(int i=0;i<R;i++)
for(int j=0;j<C;j++)
cin>>Map[i][j];
for(int i=0;i<R;i++)
for(int j=0;j<C;j++){
if(Map[i][j]=='#'){
DFS(i,j);
ans++;
}
}
printf("%d\n",ans);
}
return 0;
}

Best Grass的更多相关文章

  1. hdu----(1849)Rabbit and Grass(简单的尼姆博弈)

    Rabbit and Grass Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  2. hdu 1849(Rabbit and Grass) 尼姆博弈

    Rabbit and Grass Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  3. hdu 1849 Rabbit and Grass 博弈论

    水题,转化Nim 代码如下: #include<iostream> #include<stdio.h> #include<algorithm> #include&l ...

  4. 10382 - Watering Grass

    Problem E Watering Grass Input: standard input Output: standard output Time Limit: 3 seconds n sprin ...

  5. Rabbit and Grass(杭电1849)(尼姆博弈)

    Rabbit and Grass Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  6. HDU 1849 Rabbit and Grass

    题解:因为棋子可重叠,所以就等于取石子问题,即尼姆博弈,SG[i]=i,直接将输入数据异或即可. #include <cstdio> int main(){ int SG,n,a; whi ...

  7. HDU1849 Rabbit and Grass()

    用异或看取得的值是否为0推断 思想换没搞懂 #include<stdio.h> int main() { int ans,n,a; while(scanf("%d",& ...

  8. [补档][Usaco2015 Jan]Grass Cownoisseur

    [Usaco2015 Jan]Grass Cownoisseur 题目 给一个有向图,然后选一条路径起点终点都为1的路径出来,有一次机会可以沿某条边逆方向走,问最多有多少个点可以被经过? (一个点在路 ...

  9. Grass Cownoisseur[Usaco2015 Jan]

    题目描述 In an effort to better manage the grazing patterns of his cows, Farmer John has installed one-w ...

随机推荐

  1. TCP/IP协议学习之实例ping命令学习笔记

    TCP/IP协议学习之实例ping命令学习笔记(一) 一. 目的为了让网络协议学习更有效果,在真实网络上进行ping命令前相关知识的学习,暂时不管DNS,在内网中,进行2台主机间的ping命令的整个详 ...

  2. java多维数组

    int a[][][] = {{{1,2},{1,2}},{{1,2},{1,2}}}; int b[][][] = new int[][][]{{{1,2},{1,2}},{{1,2},{1,2}} ...

  3. JavaScript join() 方法

    http://www.w3school.com.cn/jsref/jsref_shift.asp JavaScript Array 对象 定义和用法 join() 方法用于把数组中的所有元素放入一个字 ...

  4. 无论url请求什么.都可以拼接class类名.实例化.传递get参数-->给当前控制器-->传递给抽象父类-->都交给抽象父类.这个方法去处理call_user_func_array()

    <?phpdefine('DS','/');define('A_PATH',str_replace('\\','/',dirname(__FILE__)).DS); //01获取到主程序目录cl ...

  5. 如何使用 AngularJS 的 ngShow 和 ngHide

    今天我们来看看怎样使用Angular的ngShow 和ngHide 指令来完成它们听起来应该完成的,显示和隐藏! 它们应该做的事 ngShow 和ngHide 允许我们显示或隐藏不同的元素.这有助于创 ...

  6. Android Studio 如何使用jni

    在project视图下,main文件夹下,创建jniLibs文件夹,然后把so文件放入即可:

  7. php根据时间显示刚刚,几分钟前,今天,昨天的实现代码

    如果大家有更好的方案欢迎交流 function diffBetweenTwoDay($pastDay){ $timeC = time() - strtotime($pastDay); $dateC = ...

  8. 笨方法学python--简介

    该章提到编程新手所需的三种最重要的技术:读和写,注重细节,发现不同. 读 和 写 即熟悉代码中的各种字符. 注 重 细 节 将例子一字不差地打出来,通过实践训练自己 发 现 不 同 这个是通过长年累月 ...

  9. junit 单元测试 - 参数化测试

    junit4.x版本需要引入如下jar包: hamcrest-core-1.3.jar junit-4.12-beta-3.jar 新建一个计算器类,如下: package com.pt; publi ...

  10. IDL和生成代码分析

    IDL:接口描述语言 这里使用thrift-0.8.0-xsb这个版本来介绍IDL的定义以及简单实例分析. 1. namespace 定义包名 2.struct 结构体,定义服务接口的参数和返回值用到 ...