红与黑

   题目大意:一个人在一个矩形的房子里,可以走黑色区域,不可以走红色区域,从某一个点出发,他最多能走到多少个房间?

   不多说,DFS深搜即可,水题

   注意一下不要把行和列搞错就好了,我就是那样弄错过一次哈哈哈哈

   

 #include <stdio.h>
#include <stdlib.h>
#define MAX_N 20 static int dp[MAX_N][MAX_N];
static int startx;
static int starty;
static int ans; void DFS_Search(const int, const int, const int, const int); int main(void)
{
int W, H, i, j;
while (~scanf("%d%d", &W, &H))
{
if (W == && H == )
break;
ans = ;//先算起点的
for (i = ; i < H; i++)//Read Map
{
getchar();
for (j = ; j < W; j++)
{
scanf("%c", &dp[i][j]);
if (dp[i][j] == '@'){
startx = i; starty = j;
}
}
}
DFS_Search(startx, starty, W, H);
printf("%d\n", ans);
} return ;
} void DFS_Search(const int x, const int y, const int W, const int H)
{
dp[x][y] = '#';
ans++;
if (x - >= && dp[x - ][y] != '#')
DFS_Search(x - , y, W, H);
if (x + < H && dp[x + ][y] != '#')
DFS_Search(x + , y, W, H);
if (y - >= && dp[x][y - ] != '#')
DFS_Search(x, y - , W, H);
if (y + < W && dp[x][y + ] != '#')
DFS_Search(x, y + , W, H);
}

DFS:Red and Black(POJ 1979)的更多相关文章

  1. Red and Black(poj 1979 bfs)

    Red and Black Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 27891   Accepted: 15142 D ...

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

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

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

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

  4. poj 1979 Red and Black(dfs)

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

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

  6. poj 1979 Red and Black(dfs水题)

    Description There is a rectangular room, covered with square tiles. Each tile is colored either red ...

  7. 【POJ - 1979 】Red and Black(dfs+染色)

    -->Red and Black Descriptions: 有个铺满方形瓷砖的矩形房间,每块瓷砖的颜色非红即黑.某人在一块砖上,他可以移动到相邻的四块砖上.但他只能走黑砖,不能走红砖. 敲个程 ...

  8. POJ 1979 Red and Black【DFS】

    标准DFS,统计遍历过程中遇到的黑点个数 #include<cstdio> #include<vector> #include<queue> #include< ...

  9. POJ 1979 Red and Black (DFS)

    Description There is a rectangular room, covered with square tiles. Each tile is colored either red ...

随机推荐

  1. 【poj1088】 滑雪

    http://poj.org/problem?id=1088 (题目链接) 题意 给出一个矩阵,任意选择一个起点,每次只能向周围4个格子中的值比当前格子小的格子移动,求最多能移动多少步. Soluti ...

  2. codevs3243 区间翻转

    题目描述 Description 给出N个数,要求做M次区间翻转(如1 2 3 4变成4 3 2 1),求出最后的序列 输入描述 Input Description 第一行一个数N,下一行N个数表示原 ...

  3. form表单只提交数据而不进行页面跳转的解决方案

    一般的form提交操作写法为 代码如下: <form action="saveReport.htm" method="post"> …… <i ...

  4. Effective Java之最佳建议

    #Effective Java之最佳建议 此书中,目前给我帮助最大的两条建议是: - 检查参数的有效性 - 不要忽略异常 ###检查参数的有效性 对于这一条,使我感同身受的原因是:在Web项目中,前期 ...

  5. 让VisualVM+BTrace进入unsafe mode

    让VisualVM+BTrace进入unsafe mode http://kenai.com/projects/btrace/pages/UserGuide BTrace很强大,但有很多安全限制,比如 ...

  6. make -e install ,,,make命令的-e选项!

    -e, --environment-overrides Environment variables override makefiles.环境变量覆盖Makefile文件. 用这个时,一般都自己编写s ...

  7. centos安装软件Error: Cannot find a valid baseurl for repo: base

    今天使用yum安装软件,出现下面的提示: Loaded plugins: fastestmirror, refresh-packagekit, securityLoading mirror speed ...

  8. iOS7: 如何获取不变的UDID

    如何使用KeyChain保存和获取UDID 本文是iOS7系列文章第一篇文章,主要介绍使用KeyChain保存和获取APP数据,解决iOS7上获取不变UDID的问题.并给出一个获取UDID的工具类,使 ...

  9. PHP访问,增删改查,小结

    PHP访问数据,增,删,改,查 增: 1,add.php 显示页面,利用 <form> 表单添加数据,数据添加到 name 中. 2,addchuli.php 处理页面,定义变量接受 $_ ...

  10. 如何更改firefox默认搜索引擎?一步搞定!

    由于开发设计的需要,ytkah平时习惯使用firefox作为默认浏览器,火狐浏览器可添加的扩展功能比较,比如firebug.nofollow.seoquake等,还有比较友好的功能就是选中关键词拖动直 ...