POJ 1979
这是一道比较水的DPS的题目
题意就是求你可以走到的黑色的地板砖的块数,@代表你的起点,也是黑色的地板砖,#代表白色的,则说明你不能走,这就是一个广搜的题目
思路也很简单,如果你周围的那块地板是黑色的,而且之前没有走过,那就可以往那个地板砖走。
还有这道题的那个初始化很重要,不然很可能会WA。
#include <stdio.h>
#include <iostream>
#include <string.h> using namespace std; int ans;
bool mark[][];
char str_1[][];
void dfs(int m,int n)
{
if(str_1[m+][n]=='.'&&mark[m+][n]){mark[m+][n]=false;ans++;dfs(m+,n);}
if(str_1[m][n+]=='.'&&mark[m][n+]){mark[m][n+]=false;ans++;dfs(m,n+);}
if(str_1[m-][n]=='.'&&mark[m-][n]){mark[m-][n]=false;ans++;dfs(m-,n);}
if(str_1[m][n-]=='.'&&mark[m][n-]){mark[m][n-]=false;ans++;dfs(m,n-);}
} int main()
{
int m,n;
while(scanf("%d%d",&m,&n),m!=&&n!=)
{
for(int i=;i<=n;i++)
scanf("%s",str_1[i]);
memset(mark,true,sizeof(mark));
ans=;
for(int i=;i<=n;i++)
for(int j=;j<m;j++)
if(str_1[i][j]=='@') dfs(i,j);
printf("%d\n",ans);
memset(str_1,,sizeof(str_1));
}
return ;
}
POJ 1979的更多相关文章
- POJ 1979 Red and Black (红与黑)
POJ 1979 Red and Black (红与黑) Time Limit: 1000MS Memory Limit: 30000K Description 题目描述 There is a ...
- POJ 1979 Red and Black dfs 难度:0
http://poj.org/problem?id=1979 #include <cstdio> #include <cstring> using namespace std; ...
- POJ 1979 dfs和bfs两种解法
fengyun@fengyun-server:~/learn/acm/poj$ cat 1979.cpp #include<cstdio> #include<iostream&g ...
- OpenJudge/Poj 1979 Red and Black / OpenJudge 2816 红与黑
1.链接地址: http://bailian.openjudge.cn/practice/1979 http://poj.org/problem?id=1979 2.题目: 总时间限制: 1000ms ...
- poj 1979 Red and Black(dfs)
题目链接:http://poj.org/problem?id=1979 思路分析:使用DFS解决,与迷宫问题相似:迷宫由于搜索方向只往左或右一个方向,往上或下一个方向,不会出现重复搜索: 在该问题中往 ...
- POJ 1979 DFS
题目链接:http://poj.org/problem?id=1979 #include<cstring> #include<iostream> using namespace ...
- POJ 1979 红与黑
题目地址: http://poj.org/problem?id=1979 或者 https://vjudge.net/problem/OpenJ_Bailian-2816 Red and Blac ...
- POJ 1979 Red and Black (zoj 2165) DFS
传送门: poj:http://poj.org/problem?id=1979 zoj:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problem ...
- poj 1979 Red and Black 题解《挑战程序设计竞赛》
地址 http://poj.org/problem?id=1979 Description There is a rectangular room, covered with square tiles ...
- POJ 1979 Red and Black
#include<iostream> #include<cstdio> #include<queue> #include<algorithm> #inc ...
随机推荐
- SSL、OPENSSL、SSH、OPENSSH
SSL(Secure Sockets Layer 安全套接层),及其继任者传输层安全(Transport Layer Security,TLS)是为网络通信提供安全及数据完整性的一种安全协议.TLS与 ...
- RabbitMQ service is already present - only updating service parameters
如果你安装RabbitMQ不是那么一番顺利..那么你有可能会重装多次.. So..问题来了..重装时你执行 rabbitmq-service install 的时候..有可能就会报这个错了.. ...
- git在windows命令行下使用
“不是内部或外部命令,也不是可运行的程序”,通常要将程序的exe路径配置环境变量. 将git的bin目录的路径添加到环境变量path中即可.
- ELK日志分析系统(转)
原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 .作者信息和本声明.否则将追究法律责任.http://467754239.blog.51cto.com/4878013/1700828 ...
- nyoj 171 聪明的kk
聪明的kk 时间限制:1000 ms | 内存限制:65535 KB 难度:3 描述 聪明的“KK”非洲某国展馆的设计灵感源于富有传奇色彩的沙漠中陡然起伏的沙丘,体现出本国不断变换和绚丽多彩的 ...
- svn搬移到gitlab及使用
svn是一款非常简便,易用的源代码管理工具,用了这么多年,对它情有独钟.都说习惯最难改,那为何要搬移到gitlab上呢? 喜欢尝试新东西,前提还是git比较强大,svn有的它都有,svn没有的它也有. ...
- Lexicography(数学推论>>求按字典序排第k个排列)
Lexicography Time Limit:1000MS Memory Limit:131072KB 64bit IO Format:%lld & %llu Submit ...
- 小心一些,断言可能让你的造成循环引用NSAssert
block和self的相互引用造成的循环引用,想必大家都是明白的.上下面的代码(截取部分) __weak typeof(self) weakSelf = self; self.jsBridgeFunc ...
- js中的json
1.什么是JSON? JSON 指的是 JavaScript 对象表示法(JavaScript Object Notation) JSON 是轻量级的文本数据交换格式 2.JSON语法是JavaScr ...
- android GestureDetector 手势基础
1. 当用户触摸屏幕的时候,会产生许多手势,例如down,up,scroll,filing等等,我们知道View类有个View.OnTouchListener内部接口,通过重写他的onTouch(Vi ...