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 ...
随机推荐
- 用C实现字符串分割并返回所有子串
#include <stdio.h>#include <stdlib.h>#include <unistd.h>#include <string.h> ...
- 初识cross apply & outer apply
1. 2. 3.参考地址: http://blog.csdn.net/htl258/article/details/4537421
- [POJ] 2453 An Easy Problem [位运算]
An Easy Problem Description As we known, data stored in the computers is in binary form. The probl ...
- MySQL表复制
http://www.2cto.com/database/201202/120259.html http://www.cnblogs.com/sunss/archive/2010/10/08/1845 ...
- BZOJ 1068 (区间DP)
题意:字符串的压缩,f[l][r][0]代表还没M,f[l][r][1]代表有M. #include<cstdio> #include<cmath> #include<c ...
- 《Programming WPF》翻译 第9章 5.默认可视化
原文:<Programming WPF>翻译 第9章 5.默认可视化 虽然为控件提供一个自定义外观的能力是有用的,开发者应该能够使用一个控件而不用必须提供自定义可视化.这个控件应该正好工作 ...
- 划分树 poj2104 hdu5249
KPI Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submis ...
- 我在使用vector时候遇到的二逼问题
最近在练习使用STL中德各种容器,像vector,map,set之类的. 然后在使用vector的时候,无意间遇到了一个很二逼的问题. 主要是这样的,请看源码(C++): //错误的写法: #incl ...
- oracle数据库recover和restore的区别
restore just copy the physical file, recover will consistent the database.restore 是还原,文件级的恢复.就是物理文件还 ...
- css中的伪类
伪类用于向某些选择器添加一些特殊效果. 1):focus 伪类在元素获得焦点的时向元素添加特殊样式.一般用于输入文本域,按钮,以及超链接. a:focus{color:red;}超链接字体为红色 in ...