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. PHP signal 信号

    最早写php时,发现在终端执行一个php文件,会一直等待程序执行完成以后,终端才能继续下面的操作,若不小心按了下Ctrl+C会导致php程序退出,闭避免这种情况发生,将会使用php的系统编程,即sig ...

  2. bzoj1977

    1977: [BeiJing2010组队]次小生成树 Tree Time Limit: 10 Sec  Memory Limit: 512 MBSubmit: 3001  Solved: 751[Su ...

  3. 如何将excel导入到数据库中并在gridview中显示

    在页面上导入个excel文件,将该excel中的数据导入到数据库中,并且在页面的gridview中把数据显示出来. .在Asp.net中怎样将Excel文件中的数据导入到GridView中呢? 首先我 ...

  4. Java多线程之~~~使用Exchanger在线程之间交换数据[这个结合多线程并行会有解决很多问题]生产者消费者模型

    http://blog.csdn.net/a352193394/article/details/39503857  Java多线程之~~~使用Exchanger在线程之间交换数据[这个结合多线程并行会 ...

  5. 用 openSSL 生成 公钥 私钥

    支付宝app接口需要 RSA加密通讯 https://doc.open.alipay.com/doc2/detail?treeId=58&articleId=103242&docTyp ...

  6. 还在纠结 Flux 或 Relay,或许 Redux 更适合你

    重磅消息,Redux 1.0 发布,终于可以放心用于生产环境了! 在这个端应用技术膨胀的时代,每天都有一大堆框架冒出,号称解决了 XYZ 等一系列牛 X 的问题,然后过一段时间就不被提起了.但开发的应 ...

  7. sql server中单引号拼接字符串(书写错误会出现错误"浮点值 XXXX 超出了计算机表示范围(8 个字节)。“XX”附近有语法错误。")

    " ' "(单引号)的运用:在sql server中,两个" ' "(单引号)在拼接字符串的情况下运用,就是表示拼接上了一个" ' "单引号 ...

  8. 收缩sql server数据库日志

    项目中,可能数据库(sql server数据库)日志太多,占了很多磁盘空间,可以通过收缩数据库日志,减少日志文件大小. 下面以Northwind数据库为例: 1.把数据库的恢复模式设置为“简单模式”: ...

  9. servlet多次跳转报IllegalStateException异常

    当发生在如下错误的时候,有一个方案可行, "java.lang.IllegalStateException: Cannot forward after response has been c ...

  10. eclipse无法导入已有android项目

    问题: 今天发现我拷贝的一个android项目无法导入到eclipse,但是其它的已有android项目却可以导入 思路 现在网络这么流行,当然是上网查,得益于eclipse无法导入Android工程 ...