春天到了,师大的园丁们又开始忙碌起来了.

京师广场上有一块空地,边界围成了一个多边形,内部被划分成一格一格的.园丁们想在这个多边形内的每一格内种植一些花.

现在请你帮忙计算一下一共最多可以种多少花.

广场用一个M*N的字符数组表示,"."和"*"代表一个方格,其中"*"代表空地的边界,"."是空格,只有边界内部的空格才能用于种花.
一个空格位于边界内部,当且仅当由该点出发只允许向上、下、左、右四个方向移动,最终都会遇到边界。

例如下面就是一个6*7的广场

.......
..***..
..*..*.
..*..*.
...**..
.......

种花方案如下(数字代表的地方)
.......
..***..
..*12*.
..*34*.
...**..
.......

 

Input

输入数据第一行是M和N(M和N不超过100),代表有广场的大小
接下来就是一个M*N的字符矩阵,是广场的表示

 

Output

对应于输入数据,输出一个整数,给出输入的情形能够种的花数目.

 

Sample Input

6 7
.......
..***..
..*..*.
..*..*.
...**..
.......
5 7
.......
..***..
..*.*..
..***..
.......

Sample Output

4
1 一般想得到的方法是搜索大法,当然这道题也可以直接暴力循环
#include<stdio.h>
int k[][];
char l[];
int n,m;
int x[]={-,,,},y[]={,-,,};
void dfs(int a,int b)
{
for(int i=;i<;i++)
{
int xx=a+x[i];
int yy=b+y[i];
if(xx>-&&xx<n&&yy>-&&yy<m&&k[xx][yy]!=)
{
k[xx][yy]=;
dfs(xx,yy);
}
}
}
int main()
{ while(scanf("%d%d",&n,&m)!=EOF)
{int flag=,p,q;
for(int i=;i<n;i++)
{ scanf("%s",l); for(int j=;j<m;j++) {
if(l[j]=='.')
k[i][j]=;
else k[i][j]=;
}
}
for(int i=;i<m;i++)
{
if(k[][i]==)
{
k[][i]=;
dfs(,i);
}
if(k[n-][i]==)
{
k[n-][i]=;
dfs(n-,i);
}
}
for(int i=;i<n-;i++)
{
if(k[i][]==)
{
k[i][]=;
dfs(i,);
}
if(k[i][m-]==)
{
k[i][m-]=;
dfs(i,m-);
}
}
int sum=;
for(int i=;i<n;i++)
for(int j=;j<m;j++)
if(k[i][j]==)
sum++; printf("%d\n",sum); }
}

BNUOJ 1038 Flowers的更多相关文章

  1. bnuoj 33656 J. C.S.I.: P15(图形搜索题)

    http://www.bnuoj.com/bnuoj/problem_show.php?pid=33656 [题解]:暴力搜索题 [code]: #include <iostream> # ...

  2. CF451E Devu and Flowers (隔板法 容斥原理 Lucas定理 求逆元)

    Codeforces Round #258 (Div. 2) Devu and Flowers E. Devu and Flowers time limit per test 4 seconds me ...

  3. poj 3262 Protecting the Flowers

    http://poj.org/problem?id=3262 Protecting the Flowers Time Limit: 2000MS   Memory Limit: 65536K Tota ...

  4. Codeforces Round #381 (Div. 2)B. Alyona and flowers(水题)

    B. Alyona and flowers Problem Description: Let's define a subarray as a segment of consecutive flowe ...

  5. poj1157LITTLE SHOP OF FLOWERS

    Description You want to arrange the window of your flower shop in a most pleasant way. You have F bu ...

  6. BNUOJ 52325 Increasing or Decreasing 数位dp

    传送门:BNUOJ 52325 Increasing or Decreasing题意:求[l,r]非递增和非递减序列的个数思路:数位dp,dp[pos][pre][status] pos:处理到第几位 ...

  7. 【BZOJ 1038】【ZJOI 2008】瞭望塔

    http://www.lydsy.com/JudgeOnline/problem.php?id=1038 半平面交裸题,求完半平面后在折线段上的每个点竖直向上和半平面上的每个点竖直向下求距离,统计最小 ...

  8. POJ 1038 Bugs Integrated, Inc.

    AC通道 神坑的一道题,写了三遍. 两点半开始写的, 第一遍是直接维护两行的二进制.理论上是没问题的,看POJ discuss 上也有人实现了,但是我敲完后准备开始调了.然后就莫名其妙的以为会超时,就 ...

  9. CF459B Pashmak and Flowers (水

    Pashmak and Flowers Codeforces Round #261 (Div. 2) B. Pashmak and Flowers time limit per test 1 seco ...

随机推荐

  1. emmet 缩写API

    http://docs.emmet.io/cheat-sheet/

  2. java操作xml

    package com.xml.zh; import javax.xml.parsers.*; import org.w3c.dom.*; public class XmlTest1{ /** * 使 ...

  3. php empty()和isset()的区别

    在使用 php 编写页面程序时,我经常使用变量处理函数判断 php 页面尾部参数的某个变量值是否为空,开始的时候我习惯了使用 empty() 函数,却发现了一些问题,因此改用 isset() 函数,问 ...

  4. Jquery-控制table的奇偶数色列

    css代码 <style> .even{background:#FFF38F;} .odd{background:#FFFFEE;} .selected{background:#FF990 ...

  5. 宿主机( win 7 系统) ping 虚拟机VMware( cent os 6.6 ) 出现“请求超时”或者“无法访问目标主机”的解决方法

    首先虚拟机的网络连接设置为"Host-only": 然后在 cmd 窗口中查看 VMnet1 的 ip 地址,这里是 192.168.254.1 接下来在 Linux 中设置网卡地 ...

  6. TCP/IP详解 学习三

    网际协议 ip Ip 是不可靠和无连接的 ip首部 4个字节的 32 bit值以下面的次序传输:首先是 0-7 bit,其次 8-15 bit,然后 1 6-23 bit,最后是 24~31 bit. ...

  7. Linux mount/unmount命令(转)

    格式:mount [-参数] [设备名称] [挂载点] 其中常用的参数有:-a 安装在/etc/fstab文件中类出的所有文件系统.-f 伪装mount,作出检查设备和目录的样子,但并不真正挂载文件系 ...

  8. iOS动画中的枚举UIViewAnimationOptions

    若本帖转出“博客园”请注明出处(博客园·小八究):http://www.cnblogs.com/xiaobajiu/p/4084747.html 笔记 首先这个枚举属于UIViewAnimation. ...

  9. list的使用命令 百度经验保存

    在key对应的list的头部添加字符串元素 命令:lpush               #参数0 到-1  是从开始到结束 2 在key对应list的尾部添加字符串元素: 命令:rpush 3 在k ...

  10. SQL injection

    SQL injection is a code injection technique, used to attack data-driven applications, in which malic ...