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. 关于Unity中的涉及到Attribute的相关概念整理(@WhiteTaken)

    这两天事情比较多,没有来得及更新,现在把我这两天看的attributes相关内容进行整理. 涉及到的相关概念包括: C#中的特性概念及用法 创建自己的特性以及通过反射访问特性 C#中的特性概念以及用法 ...

  2. vbs 获取当前目录的实现代码

    CMD当前路径 复制代码 代码如下: test = createobject("Scripting.FileSystemObject").GetFolder(".&quo ...

  3. cp 覆盖 \cp a test\a

    使用cp命令覆盖文件总是提示要输入yes或no,一个两个就算了,大量的文件复制就不行了,即使加上-f参数也无法强行覆盖.苦思冥想不得解,终于在查阅了众多资料后让我找到了解决方法,这里写出来,让有同样困 ...

  4. JavaScript高级程序设计:第九章

    第九章 一.使用能力检测 能力检测的目标不是识别特定的浏览器,而是识别浏览器的能力.能力检测的基本模式如下: if ( object.propertyInQuestion ) { //使用object ...

  5. Myeclipse8.6安装freemarker插件

    1. 打开http://sourceforge.net/projects/freemarker-ide/files/ 下载最新版本,目前本人下载时最新版本是:freemarker-ide-0.9.14 ...

  6. dede 转 帝国

    1.转换栏目 insert into ak_enewsclass (classid,bclassid,classname,myorder,classpath,intro,classpagekey) s ...

  7. PHP中字符串转换为数值 可能会遇到的坑

    今天看到一个老外最喜欢的一段代码 <?php $string = 'zero'; $zero = 0; echo ($string == $zero) ? 'Why? Just why?!' : ...

  8. 非root启动80端口

    Linux非root用户如何使用80端口启动程序   默认情况下Linux的1024以下端口是只有root用户才有权限占用,我们的tomcat,apache,nginx等等程序如果想要用普通用户来占用 ...

  9. 'customerService' for bean class [com.cd.service.business.customer.impl.CustomerService]

    'customerService' for bean class [com.cd.service.business.customer.impl.CustomerService] 此处报错是因为我 把一 ...

  10. 在PL/SQL/sqlplus客户端 中如何让程序暂停几秒钟

    1. how to check procedure exist: SQL> conn oper/oper123Connected.SQL> desc dbms_lock;PROCEDURE ...