红与黑

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

   不多说,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. 【BZOJ-2223】PATULJCI 可持久化线段树

    2223: [Coci 2009]PATULJCI Time Limit: 10 Sec  Memory Limit: 259 MBSubmit: 728  Solved: 292[Submit][S ...

  2. BZOJ-1050 旅行comf 并查集+乱搞

    好久以前codevs上做过的,拿着改了改.. 1050: [HAOI2006]旅行comf Time Limit: 10 Sec Memory Limit: 162 MB Submit: 2194 S ...

  3. TYVJ P2002 扑克牌

    背景 Admin生日那天,Rainbow来找Admin玩扑克牌……玩着玩着Rainbow觉得太没意思了,于是决定给Admin一个考验~~~ 描述 Rainbow把一副扑克牌(54张)随机洗开,倒扣着放 ...

  4. 51NOD 1400 序列分解

    传送门:1400 序列分解序列分解 基准时间限制:1s  空间限制:131072 KBKB131072 KB 1 秒 空间限制:131072 KB 分值: 40 难度:4级算法题1 秒 空间限制:13 ...

  5. 浅谈Dynamic 关键字系列之三(上):ExpandoObject, DynamicObject, DynamicMetaObject

    http://www.cnblogs.com/LoveJenny/archive/2011/07/05/2098578.html ExpandoObject:表示一个对象,该对象包含可在运行时动态添加 ...

  6. linux:Nginx+https双向验证(数字安全证书)

    本文由邓亚运提供 Nginx+https双向验证 说明: 要想实现nginx的https,nginx必须启用http_ssl模块:在编译时加上--with-http_ssl_module参数就ok.另 ...

  7. Spring学习2—Spring容器

    一.Spring容器接口关系 容器是Spring框架的核心,Spring容器就是一个巨大的工厂.Spring容器使用Ioc(控制反转(Inversion of Control )管理所有组成应用系统的 ...

  8. mongo操作

    详细使用网址:http://blog.csdn.net/xinghebuluo/article/details/7050811 MongoDB基本使用 成功启动MongoDB后,再打开一个命令行窗口输 ...

  9. CodeForces 705A(训练水题)

    题目链接:http://codeforces.com/problemset/problem/705/A 从第三个输出中可看出规律, I hate that I love that I hate it ...

  10. MYSQL远程登录权限设置(转)

    Mysql默认关闭远程登录权限,如下操作允许用户在任意地点登录: 1. 进入mysql,GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY ...