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. android 按钮Button单击背景切换

    res/drawable/btn_selected.xml <?xml version="1.0" encoding="utf-8"?> <s ...

  2. android异步Http框架

    首先在GitHub上下载异步Http框架代码以及相关文档: 将jar包放入lib包中即可: 接下来分别实现get.post.文件上传功能实现: 代码实现如下: AsyncHttpClient clie ...

  3. redis运维的一些知识点

    恰好看到一些redis需要主要的东西 记下 供参考 原文地址 http://hi.baidu.com/ywdblog/item/1a8c6ed42edf01866dce3fe3 最近在线上实际使用了一 ...

  4. JS电子文档链接

    http://www.oschina.net/translate/learning-javascript-design-patterns   学用 JavaScript 设计模式 http://es6 ...

  5. how to use the curses library in unix?

    In linux, you can use the ncurses library to use the terminal as a text buffer: move the cursor arou ...

  6. 公司用中会用到的iOS开源库和第三方组件(不断更新...)

    分享一些目前我个人接触到的一些第三方组件和开源的库, 感谢开源, 减少了我们的开发成本, 节约了我们大量的时间, 让我们有更多的时间和精力专注做我们自己的产品.总有没有接触过的 , 总有你会用到的 , ...

  7. zend笔记

    ZEND_STRL(str)  等价于 (str), (sizeof(str)-1) ZEND_STRS(str)等价于 (str), (sizeof(str))

  8. Learn about images & containers

    Learn about images & containers Docker Engine provides the core Docker technology that enables i ...

  9. 今天修改 wifi hal 的时候碰见一个问题

    今天修改 supplicant_name的时候出现一个问题. 发现原来init.wifi.rc 的server的时候出现了一个问题. 名字不对,没有和 supplicant_name对应起来. 所以就 ...

  10. android版本 busybox

    http://www.busybox.net/downloads/binaries/1.21.1/  根据不同的平台选择busybox已经编译好的