BNUOJ flower (搜索)
京师广场上有一块空地,边界围成了一个多边形,内部被划分成一格一格的.园丁们想在这个多边形内的每一格内种植一些花.
现在请你帮忙计算一下一共最多可以种多少花.
广场用一个M*N的字符数组表示,"."和"*"代表一个方格,其中"*"代表空地的边界,"."是空格,只有边界内部的空格才能用于种花.
一个空格位于边界内部,当且仅当由该点出发只允许向上、下、左、右四个方向移动,最终都会遇到边界。
例如下面就是一个6*7的广场
.......
..***..
..*..*.
..*..*.
...**..
.......
种花方案如下(数字代表的地方)
.......
..***..
..*12*.
..*34*.
...**..
.......
Input
接下来就是一个M*N的字符矩阵,是广场的表示
Output
Sample Input
Sample Input1
6 7
.......
..***..
..*..*.
..*..*.
...**..
.......
Sample Input2
5 7
.......
..***..
..*.*..
..***..
.......
Sample Output
Sample Output1
4
Sample Output2
1
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
using namespace std;
int map[][];
int dirx[]={,-,,};
int diry[]={,,-,};
int m,n;
int dfs(int x,int y)
{
int i,j,dx,dy;
if(x<||x>m+||y<||y>n+||map[x][y]==)
return ;
map[x][y]=;
for(i=;i<;i++)
{
dx=x+dirx[i];
dy=y+diry[i];
dfs(dx,dy);
}
return ;
}
int main()
{
int i,j;
//freopen("in.txt","r",stdin);
while(cin>>m>>n)
{
char s;
bool flag=;
int sum=;
memset(map,,sizeof(map));
for(i=;i<=m;i++)
{
for(j=;j<=n;j++)
{
cin>>s;
map[i][j]=(s=='.'?:);
}
}
dfs(,);
for(i=;i<=m;i++)
{
for(j=;j<=n;j++)
if(map[i][j])
sum++;
}
cout<<m*n-sum<<endl;
}
}
BNUOJ flower (搜索)的更多相关文章
- bnuoj 33656 J. C.S.I.: P15(图形搜索题)
http://www.bnuoj.com/bnuoj/problem_show.php?pid=33656 [题解]:暴力搜索题 [code]: #include <iostream> # ...
- bnuoj 31796 键盘上的蚂蚁(搜索模拟)
http://www.bnuoj.com/bnuoj/contest_show.php?cid=2876#problem/31796 [题意]: 如题,注意大小写情况 [code]: #include ...
- BNUOJ 52325 Increasing or Decreasing 数位dp
传送门:BNUOJ 52325 Increasing or Decreasing题意:求[l,r]非递增和非递减序列的个数思路:数位dp,dp[pos][pre][status] pos:处理到第几位 ...
- bnuoj 1071 拼图++(BFS+康拓展开)
http://www.bnuoj.com/bnuoj/problem_show.php?pid=1071 [题意]:经过四个点的顺逆时针旋转,得到最终拼图 [题解]:康拓展开+BFS,注意先预处理,得 ...
- BNUOJ-29358 Come to a spring outing 搜索,DP
题目链接:http://www.bnuoj.com/bnuoj/problem_show.php?pid=29358 状态虽然很多,但是非常稀疏,dfs搜索然后剪下枝.. 或者DP,f[i][j][k ...
- UVALIVE 5893 计算几何+搜索
题意:很复杂的题意,我描述不清楚. 题目链接:http://acm.bnu.edu.cn/bnuoj/contest_show.php?cid=3033#problem/33526 大致是,给定一个起 ...
- BNUOJ 12756 Social Holidaying(二分匹配)
题目链接:http://www.bnuoj.com/bnuoj/problem_show.php?pid=12756 Social Holidaying Time Limit: 3000ms Memo ...
- 搜索水题四连发_C++
特别声明:以下题目有部分为原创题,涉及版权问题,不得转载,违者追究 法律责任! 话说这是一套神题,只有你想不到,没有你做不到 题目更正后比 Pascal 跑得还快哈~ 一道特别裸,但是特别坑的搜索题 ...
- matlab查找最临近搜索knnsearch
Idx = knnsearch(X,Y) finds the nearest neighbor in X for each query point in Y and returns the indic ...
随机推荐
- head直接复制的
<script type="application/x-javascript"> addEventListener("load", function ...
- 如何用googletest写单元测试
http://www.uml.org.cn/c++/201203293.asp googletest是一个用来写C++单元测试的框架,它是跨平台的,可应用在windows.linux.Mac等OS平台 ...
- LeetCode_Subsets
Given a set of distinct integers, S, return all possible subsets. Note: Elements in a subset must be ...
- Keil C51必须注意的一些有趣特性
Keil c51号称作为51系列单片机最好的开发环境,大家一定都很熟悉.它的一些普通的特性大家也都了解,(书上也都说有)如:因为51内的RAM很小,C51的函数并不通过堆栈传递参数(重入函数除外),局 ...
- kibana 访问IP分布图
- UVA 11374 Airport Express(枚举+最短路)
枚举每条商业线<a, b>,设d[i]为起始点到每点的最短路,g[i]为终点到每点的最短路,ans便是min{d[a] + t[a, b] + g[b]}.注意下判断是否需要经过商业线.输 ...
- JQuery 动画之 广告
html页面: <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head&g ...
- 如何在cmd窗口启动Tomcat
平时,一般使用tomcat/bin/startup.bat目录在windows环境启动Tomcat,或者使用IDE配置后启动. 下面来简单介绍下如果在cmd窗口直接输入命令启动Tomcat: 1.将t ...
- 【多线程】--生产者消费者模式--Lock版本
在JDK1.5发布后,提供了Synchronized的更优解决方案:Lock 和 Condition 我们使用这些新知识,来改进例子:[多线程]--生产者消费者模式--Synchronized版本 改 ...
- Javascript常用正则表达式
一.校验数字的表达式 数字:^[0-9]*$ n位的数字:^\d{n}$ 至少n位的数字:^\d{n,}$ m-n位的数字:^\d{m,n}$ 零和非零开头的数字:^(0|[1-9][0-9]*)$ ...