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. python学习之路-11 多线程、多进程、协程

    python内置队列模块 queue queue的四种队列 q = queue.Queue() # 先进先出队列 q = queue.LifoQueue() # 后进先出队列 q = queue.Pr ...

  2. hdoj 3400 三分

    两次三分 #include <iostream> #include <cstdio> #include <cstring> #include <cmath&g ...

  3. 关于c语言的一个小bug(c专家编程)

    不多说,说了都是累赘!直接看代码吧! #include <stdio.h> int array[] = {23, 34, 12, 17, 204, 99, 16}; #define TOT ...

  4. Cocos2d-x 3.0rc0版本号项目的创建和部署

    <1>执行setup.py 依照提示.加入你须要加入的环境变量 <2>创建项目批处理文件Create-Cocos2d-x 3.0-Project.bat 内容例如以下: @ec ...

  5. linux 系统下配置安装 java jdk 图文流程

    先查看一下系统版本,本例采用的操作系统是CentOS 6.5: 如果你是初装之后的操作系统,那么有可能wget这个组件是不存在的,所以你要安装一下它,这样才可以让你从网上down下你要的安装包: 上面 ...

  6. CentOs7下systemd管理知识要点

    centOs7的一个巨大的变动就是用systemd取代了原来的System V init.systemd是一个完整的软件包,安装完成后有很多物理文件组成,大致分布为,配置文件位于/etc/system ...

  7. 利用MetaWeblog API 自制博客发布小工具

    博客园提供了诸多数据接口, 利用这些接口可以很容易的实现博客的发布,修改,删除等 1.需要引用一个DLL:为CookComputing.XmlRpcV2 2.新建一个类,在其中是一些要实现的东西,如: ...

  8. Canvas Api简介1

    canvas canvas 其实对于HTML来说很简单,只是一个标签元素而已,自己并没有行为,但却把一个绘图 API 展现给客户端 JavaScript 以使脚本能够把想绘制的东西都绘制到一块画布上, ...

  9. uva 1596 Bug Hunt

    In this problem, we consider a simple programming language that has only declarations of one-dimensi ...

  10. Qt调用外部程序QProcess通信

    mainwindow.cpp文件: -------------------------------- #include "mainwindow.h" #include " ...