BNUOJ 1038 Flowers
春天到了,师大的园丁们又开始忙碌起来了.
京师广场上有一块空地,边界围成了一个多边形,内部被划分成一格一格的.园丁们想在这个多边形内的每一格内种植一些花.
现在请你帮忙计算一下一共最多可以种多少花.
广场用一个M*N的字符数组表示,"."和"*"代表一个方格,其中"*"代表空地的边界,"."是空格,只有边界内部的空格才能用于种花.
一个空格位于边界内部,当且仅当由该点出发只允许向上、下、左、右四个方向移动,最终都会遇到边界。
例如下面就是一个6*7的广场
.......
..***..
..*..*.
..*..*.
...**..
.......
种花方案如下(数字代表的地方)
.......
..***..
..*12*.
..*34*.
...**..
.......
Input
接下来就是一个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的更多相关文章
- bnuoj 33656 J. C.S.I.: P15(图形搜索题)
http://www.bnuoj.com/bnuoj/problem_show.php?pid=33656 [题解]:暴力搜索题 [code]: #include <iostream> # ...
- CF451E Devu and Flowers (隔板法 容斥原理 Lucas定理 求逆元)
Codeforces Round #258 (Div. 2) Devu and Flowers E. Devu and Flowers time limit per test 4 seconds me ...
- poj 3262 Protecting the Flowers
http://poj.org/problem?id=3262 Protecting the Flowers Time Limit: 2000MS Memory Limit: 65536K Tota ...
- 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 ...
- poj1157LITTLE SHOP OF FLOWERS
Description You want to arrange the window of your flower shop in a most pleasant way. You have F bu ...
- BNUOJ 52325 Increasing or Decreasing 数位dp
传送门:BNUOJ 52325 Increasing or Decreasing题意:求[l,r]非递增和非递减序列的个数思路:数位dp,dp[pos][pre][status] pos:处理到第几位 ...
- 【BZOJ 1038】【ZJOI 2008】瞭望塔
http://www.lydsy.com/JudgeOnline/problem.php?id=1038 半平面交裸题,求完半平面后在折线段上的每个点竖直向上和半平面上的每个点竖直向下求距离,统计最小 ...
- POJ 1038 Bugs Integrated, Inc.
AC通道 神坑的一道题,写了三遍. 两点半开始写的, 第一遍是直接维护两行的二进制.理论上是没问题的,看POJ discuss 上也有人实现了,但是我敲完后准备开始调了.然后就莫名其妙的以为会超时,就 ...
- CF459B Pashmak and Flowers (水
Pashmak and Flowers Codeforces Round #261 (Div. 2) B. Pashmak and Flowers time limit per test 1 seco ...
随机推荐
- 机器学习中的矩阵方法(附录A): 病态矩阵与条件数
1. 病态系统 现在有线性系统: Ax = b, 解方程 很容易得到解为: x1 = -100, x2 = -200. 如果在样本采集时存在一个微小的误差,比如,将 A 矩阵的系数 400 改变成 4 ...
- 第十六章:脚本化HTTP
写在本章内容前: 第十五章:事件处理 涉及到到较多的文字篇幅,介于个人精力问题,暂不更新.主要包含的内容有事件类型.注册事件处理程序.事件处理程序的调用.文档加载事件.鼠标事件.鼠标滚轮事件.拖放事件 ...
- Codeforces Round #167 (Div. 2) D. Dima and Two Sequences 排列组合
题目链接: http://codeforces.com/problemset/problem/272/D D. Dima and Two Sequences time limit per test2 ...
- Day10
会议讨论 628:今天是冲刺的最后一天了,好紧张好激动,我们组还有好些个功能没实现呢,感觉崩崩哒!还要实现选择不同的专业导入不同的课表呢. 601:在修改教师帐号信息的页面要有当密码格式.用户名格式等 ...
- 网站性能工具Yslow的使用方法
Yslow是雅虎开发的基于网页性能分析浏览器插件,从年初我使用了YSlow后,改变了博客模板大量冗余代码,不仅提升了网页的打开速度,这款插件还帮助我分析了不少其他网站的代码,之前我还特意写了提高网站速 ...
- Apache MINA(一)
Apache MINA is a network application framework which helps users develop high performance and high s ...
- JS_工厂模式
<!DOCTYPE html> <html> <head> <title></title> </head> <body&g ...
- bugzilla_firefox
//本来要给火狐提交bug的,发现复现不鸟,我勒个去 <!doctype html> <html> <head> <meta charset="ut ...
- bzoj 1193 贪心
如果两点的曼哈顿距离在一定范围内时我们直接暴力搜索就可以得到答案,那么开始贪心的跳,判断两点横纵坐标的差值,差值大的方向条2,小的条1,不断做,直到曼哈顿距离较小时可以暴力求解. 备注:开始想的是确定 ...
- 【poj1010】 STAMPS
http://poj.org/problem?id=1010 (题目链接) 感到了英语深深的恶意... 题意(真的很难懂....) 第一行数字是邮票的面值,每一个数字就是一个不同的种类,哪怕面值相同. ...