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 ...
随机推荐
- Saltstack常用模块及API
Saltstack提供了非常丰富的功能模块,涉及操作系统的基础功能.常用工具支持等,更多模块信息可以查看官网模块介绍.也可以通过sys模块列出当前版本支持的模块. salt '*' sys.list_ ...
- 整理一下Entity Framework的查询
整理一下Entity Framework的查询 2012-08-30 13:41:59 标签:Entity Framework 原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 .作者信 ...
- yii2 widget示例
<?php namespace app\components; use yii\base\Widget; use yii\helpers\Html; class RctReplyWidget e ...
- mysql和oracle的区别(功能性能、选择、使用它们时的sql等对比)
一.并发性 并发性是oltp数据库最重要的特性,但并发涉及到资源的获取.共享与锁定. mysql:mysql以表级锁为主,对资源锁定的粒度很大,如果一个session对一个表加锁时间过长,会让其他se ...
- 缺陷跟踪系统Mantis Bug Tracker
缺陷管理平台Mantis,也做MantisBT,全称Mantis Bug Tracker. 项目在github的地址:https://github.com/mantisbt/mantisbt Mant ...
- 卸载金山猎豹免费WIfi后,上不了网的解决办法
进入网络和共享中心,打开网络适配器,右键无线连接,属性,就在打开属性的那个页面,在靠上的位置有个LieBao xxx Driver,卸载. 然后,打开浏览器,试试这个链接:www.baidu.com. ...
- hdu4920 Matrix multiplication 模3矩阵乘法
hdu4920 Matrix multiplication Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072/131072 ...
- caller和callee
我们先来看下caller. caller:返回一个对函数(该函数调用了当前函数)的引用. functionName.caller:functionName对象是所执行函数的名称. 说明 对于函数来说, ...
- R-数据导入
目录 键盘输入 导入文本文件 导入Excel文件 访问数据库管理系统 键盘输入 > mydata <- data.frame(age=numeric(0), gender=characte ...
- 【Go入门教程8】总结(25个关键字)
这一章我们主要介绍了Go语言的一些语法,通过语法我们可以发现Go是多么的简单,只有二十五个关键字.让我们再来回顾一下这些关键字都是用来干什么的. break default func ...