Red and Black

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 12519    Accepted Submission(s): 7753

Problem Description
There is a rectangular room, covered with square tiles. Each tile is colored either red or black. A man is standing on a black tile. From a tile, he can move to one of four adjacent tiles. But he can't move on red tiles, he can move only on black tiles.

Write a program to count the number of black tiles which he can reach by repeating the moves described above.

 
Input
The input consists of multiple data sets. A data set starts with a line containing two positive integers W and H; W and H are the numbers of tiles in the x- and y- directions, respectively. W and H are not more than 20.

There are H more lines in the data set, each of which includes W characters. Each character represents the color of a tile as follows.

'.' - a black tile
'#' - a red tile
'@' - a man on a black tile(appears exactly once in a data set)

 
Output
For each data set, your program should output a line which contains the number of tiles he can reach from the initial tile (including itself).
 
Sample Input
6 9 ....#. .....# ...... ...... ...... ...... ...... #@...# .#..#. 11 9 .#......... .#.#######. .#.#.....#. .#.#.###.#. .#.#..@#.#. .#.#####.#. .#.......#. .#########. ........... 11 6 ..#..#..#.. ..#..#..#.. ..#..#..### ..#..#..#@. ..#..#..#.. ..#..#..#.. 7 7 ..#.#.. ..#.#.. ###.### ...@... ###.### ..#.#.. ..#.#.. 0 0
 
Sample Output
45 59 6 13
简单dfs,无剪枝;
代码:
;
}

Red and Black(简单dfs)的更多相关文章

  1. POJ 1979 Red and Black (简单dfs)

    题目: 简单dfs,没什么好说的 代码: #include <iostream> using namespace std; typedef long long ll; #define IN ...

  2. POJ1979 Red and Black (简单DFS)

    POJ1979 Description There is a rectangular room, covered with square tiles. Each tile is colored eit ...

  3. poj-1979 && hdoj - 1312 Red and Black (简单dfs)

    http://poj.org/problem?id=1979 基础搜索. #include <iostream> #include <cstdio> #include < ...

  4. POJ1573(Robot Motion)--简单模拟+简单dfs

    题目在这里 题意 : 问你按照图中所给的提示走,多少步能走出来??? 其实只要根据这个提示走下去就行了.模拟每一步就OK,因为下一步的操作和上一步一样,所以简单dfs.如果出现loop状态,只要记忆每 ...

  5. 题解报告:hdu 1312 Red and Black(简单dfs)

    Problem Description There is a rectangular room, covered with square tiles. Each tile is colored eit ...

  6. HDU 1312 Red and Black (dfs)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1312 Red and Black Time Limit: 2000/1000 MS (Java/Oth ...

  7. hdu 1312:Red and Black(DFS搜索,入门题)

    Red and Black Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Tot ...

  8. HDU 1312:Red and Black(DFS搜索)

      HDU 1312:Red and Black Time Limit:1000MS     Memory Limit:30000KB     64bit IO Format:%I64d & ...

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

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

随机推荐

  1. 创建UILabel

    UILabelCreate.h #import <UIKit/UIKit.h> @interface UILabelCreate : UILabel /** * 创建UILabel 初始化 ...

  2. c#调用Excel绘制图表

    c#调用Excel需要引用命名空间 using Microsoft.Office.Interop.Excel; 由于该程序不复杂,主要是根据不同数据画表和图,画的图像也并不复杂,因为画图和画表的操作会 ...

  3. 酷狗音乐QQ显示(VC源代码)

    效果图: 原理网上有,只是都是易语言,自己分析一下.知道原理. 但近期喜欢用酷狗听课就写这个小软件认出来,你自己能够随意改动. 不说了直接丢代码.. http://pan.baidu.com/s/1q ...

  4. MFC获取当前时间

    获取按钮消息响应函数: void CTest17GetTimeDlg::OnGetTime() { // TODO: 在此添加控件通知处理程序代码 //UpdateData(true); CTime  ...

  5. 域名解析 URL转发

    URL转发 转发功能:如果您没有一台独立的服务器(也就是没有一个独立的IP地址)或者您还有一个域名B,您想访问A域名时访问到B域名的内容,这时您就可以通过URL转发来实现.url转发可以转发到某一个目 ...

  6. MongoDB学习笔记06

    在shell中删除一个集合,执行db.test.drop()或者db.runCommand({"drop":"test"}),在MongoDB中命令其实是作为一 ...

  7. Linux进程控制——exec函数族

    原文:http://www.cnblogs.com/hnrainll/archive/2011/07/23/2114854.html 1.简介 在Linux中,并不存在exec()函数,exec指的是 ...

  8. DataGridView常用功能

    最近做Winform开发,DataGridView是必不可少的控件.整理了一下用到的基本功能的设置 1.情景1:当GridView的列没有自动填充,会出现一片空白的地方,特别不美观. 设置 自动填充G ...

  9. 莫比乌斯反演题目泛做(为了对应smz的课件)

    题1:BZOJ2190 SDOI 2010 仪仗队 题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=2190 算法讨论: 我们先来考虑一个点被 ...

  10. (转) mac 下的eclipse 配置 python 2.7

    原地址: http://marsfreewill.blogspot.it/2012/08/mac-ospythonpydeveclipse.html   在MAC OS上配置Python开发环境(Py ...