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. execl csv导出

    方维js方法:function export_csv() { var inputs = $(".search_row").find("input:[type!='chec ...

  2. SEXTANTE中调用任意C++控制台程序的简单例子

    在sextante中单纯利用python或者调用sextante已有算法进行自定义开发,很多情况下速度不咋给力,同样的操作调用QGIS的C++插件比用sextante里的算法要快,有时候快的 还不止一 ...

  3. 关于asp:login控件和验证码的问题?(转)

    1.验证码页面添加.2.将这验证码页面添加到login控件中:拖曳一Login控件,将之切换到模式下,在Html源文件中在表格中密码那行后添加: <tr>    <td style= ...

  4. Nohttp网络请求数据,Post以及Get的简单实用以及设置缓存文字的的请求

    开局声明:这是基于nohttp1.0.4-include-source.jar版本写的教程 由于nohttp功能强悍,因此需要多种权限,仅仅一个联网的权限是不够的,如果只给了Internet的权限,去 ...

  5. PHP学习笔记二十四【Get Set】

    <?php Class Person{ private $n1; private $n2; private $n3; //使用__set方法来管理所有的属性 public function __ ...

  6. 关于iOS9之后的loadViewIfNeeded

    iOS9之前 有些时候因为需要手动调用loadview 但是有风险,系统不再调用viewDidLoad 所以手动调用loadview是错误的 iOS9之后出现了loadViewIfNeeded解决了这 ...

  7. winsock开发重复定义问题

    参考: VS2013使用winsock.h和winsock2.h发生冲突后的终极解决方法:http://www.cnblogs.com/Shirlies/p/5137548.html WINSOCK. ...

  8. zoj3231 Apple Transportation(最大流)

    转载请注明出处: http://www.cnblogs.com/fraud/          ——by fraud Apple Transportation Time Limit: 1 Second ...

  9. slave延迟原因及优化方法

    转载叶总:http://imysql.com/2015/04/12/mysql-optimization-case-howto-resolve-slave-delay.shtml 一般而言,slave ...

  10. No1_4.数组的基本操作_Java学习笔记

    import java.util.Arrays; public class HelloArrayOp { public static void main(String[] args) { // TOD ...