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 ...
随机推荐
- python中os/sys/platform模块区别
os:This module provides a portable way of using operating system dependent functionality. sys:This m ...
- gradle 的sourceCompatibility 与 targetCompatibility 区别
sourceCompatibility:指定编译编译.java文件的jdk版本 targetCompatibility:确保class文件与targetCompatibility指定版本,或者更新的j ...
- [Html5]sessionStorage和localStorage常见操作
摘要 [Html5]sessionStorage和localStorage的区别 索引 上篇文章简单介绍了它们的区别,已经常见的用法.那我们能通过. 或者类似dic[key]的方式访问吗?答案是当然可 ...
- 【9-2】mysql数据库学习01
mysql安装 下载社区版本MySQL软件包(地址),或者windows installer 接压缩安装包到目标路径 在系统变量Path中加入目标路径 在mysql安装路径下,修改配置文件mysql- ...
- jq 构造函数,然后再表单提交过程中对数据进行修改
先贴代码 <script type="text/javascript"> function appendText(){ var content = $("#t ...
- PHP 使用命名空间(namespace),实现自动加载
示例: #/DB/MySql.class.php也就是DB文件夹下有MySql.class.php文件 namespace DB; class MySql { public function __co ...
- [译]git add
git add git add命令把工作目录下面的有修改的文件添加的index(staging)里面去. git add告诉Git你想在下次commit的时候把什么文件包含进去. 但是, git ad ...
- List<List<double>> lsls = null; 根据double值来重新排序lsls...
"确定:Node-data = (7,2).具体是:根据x维上的值将数据排序, 6个数据的中值(所谓中值,即中间大小的值)为7, 所以Node-data域位数据点(,).这样, 该节点的分割 ...
- 如何配置和使用Spring框架的bean
1. 首先在src目录下新建beans.xml文件,该文件名可更改. 2. 编辑xml文件如下,这里需要注意的是beans的表头中信息需要根据不同的版本对应的内容不同,本例中使用的spring的版本为 ...
- 1.交通聚类:编辑距离 (Levenshtein距离)Java实现
1.最近工作中要实现用户车辆的行驶路线的聚类,由于所给的数据只有用户一天中交通卡口所监视的卡口名称 :即青岛路-威海路-济阳路 . 要通过聚类实现车辆路线的规律分析,首先要解决的是相似度问题,我们知道 ...