这是一道比较水的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的更多相关文章

  1. POJ 1979 Red and Black (红与黑)

    POJ 1979 Red and Black (红与黑) Time Limit: 1000MS    Memory Limit: 30000K Description 题目描述 There is a ...

  2. POJ 1979 Red and Black dfs 难度:0

    http://poj.org/problem?id=1979 #include <cstdio> #include <cstring> using namespace std; ...

  3. POJ 1979 dfs和bfs两种解法

      fengyun@fengyun-server:~/learn/acm/poj$ cat 1979.cpp #include<cstdio> #include<iostream&g ...

  4. OpenJudge/Poj 1979 Red and Black / OpenJudge 2816 红与黑

    1.链接地址: http://bailian.openjudge.cn/practice/1979 http://poj.org/problem?id=1979 2.题目: 总时间限制: 1000ms ...

  5. poj 1979 Red and Black(dfs)

    题目链接:http://poj.org/problem?id=1979 思路分析:使用DFS解决,与迷宫问题相似:迷宫由于搜索方向只往左或右一个方向,往上或下一个方向,不会出现重复搜索: 在该问题中往 ...

  6. POJ 1979 DFS

    题目链接:http://poj.org/problem?id=1979 #include<cstring> #include<iostream> using namespace ...

  7. POJ 1979 红与黑

    题目地址: http://poj.org/problem?id=1979  或者  https://vjudge.net/problem/OpenJ_Bailian-2816 Red and Blac ...

  8. 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 ...

  9. poj 1979 Red and Black 题解《挑战程序设计竞赛》

    地址 http://poj.org/problem?id=1979 Description There is a rectangular room, covered with square tiles ...

  10. POJ 1979 Red and Black

    #include<iostream> #include<cstdio> #include<queue> #include<algorithm> #inc ...

随机推荐

  1. CSS 简介

    CSS 简介 需要具备的基础知识 在继续学习之前,你需要对下面的知识有基本的了解: HTML XHTML CSS 概述 CSS 指层叠样式表 (Cascading Style Sheets) 样式定义 ...

  2. csrf利用EXP

    <html><body><form action="http://www.xxx.com/user/setting/email_bind.html" ...

  3. ASP.NET MVC WebGrid – Performing true AJAX pagination and sorting 【转】

    ASP.NET MVC WebGrid – Performing true AJAX pagination and sorting FEBRUARY 27, 2012 14 COMMENTS WebG ...

  4. C# Thread挂起线程和恢复线程

    前言 众所周知,Thread类中的挂起线程和恢复线程微软已标记过时,因为可能会造成问题   Resume()   恢复当前线程 已过时. Resumes a thread that has been ...

  5. easyui的textbox和validatebox的 赋值区别

    区别代码如下: textbox:$('userId').textbox('setValue','aaa'); validatebox :$('userId').val('aaa');  

  6. Makefile的学习笔记

    Makefile的学习笔记 标签: makefilewildcard扩展includeshellfile 2012-01-03 00:07 9586人阅读 评论(2) 收藏 举报  分类: Linux ...

  7. 昨天的这个先补上--这个是关于 JQ 的移动 和 渐变特效的点击事件

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...

  8. 发布自己的包到Nuget上

    1.首先下载Nuget.exe https://dist.nuget.org/index.html 2.设置环境变量  设置apikey nuget setApiKey <my_api_key& ...

  9. PHP中逻辑运算符and/or与||/&&的一个坑

    我原来以为PHP中的and和&&是一样的, 只是写法上为了可读性和美观, 事实上我错了. 这里面深藏了一个坑! 看以下代码: $bA = true; $bB = false; $b1  ...

  10. Javascript 方法大全

    一.基础知识 1 创建脚本块 1: <script language=”JavaScript”> 2: JavaScript code goes here 3: </script&g ...