Red and Black

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

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
 
Sample Output
45
59
6
13
 #include <iostream>
#include <cstdio>
using namespace std;
char a[][];
int m,n;
int count=;
void dfs(int x,int y)
{
if(a[x][y]=='.'&&x<n&&x>=&&y<m&&y>=)
{
count++;
a[x][y]='#';
dfs(x+,y);
dfs(x,y+);
dfs(x,y-);
dfs(x-,y);
}
}
int main()
{
freopen("in.txt","r",stdin);
while(scanf("%d%d",&m,&n)&&m!=&&n!=)
{
count=;
int i,j,x,y;
for(i=;i<n;i++)
{
for(j=;j<m;j++)
{
cin>>a[i][j];
if(a[i][j]=='@')
{
x=i;y=j;
}
}
}
a[x][y]='.';
dfs(x,y);
cout<<count<<endl;
}
}
 
 

Red and Black(水)的更多相关文章

  1. POJ 1979 Red and Black(水题,递归)

    一开始理解错题意了,以为是走过的砖不能再重复走,最多能走多少个黑砖,结果写的递归陷入死循环...后来才明白原来可以重复走,问可以到达的磁砖数. #include <iostream> #i ...

  2. Android 一个TextView中设置多种不同大小的字体,设置超链接

    以前项目中要是遇到这样的UI设计,都是傻不拉唧的分为三个TextView来实现,今天在微信中无意中看了一篇公众号文章,发现原来只要一个TextView就可以搞定啦,人生最悲哀的事情莫过于工作了这么久啦 ...

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

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

  4. Red and Black(dfs水)

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

  5. 兼容Android的水波纹效果

    Android的水波纹效果只有高版本才有,我们希望自己的应用在低版本用低版本的阴影,高版本用水波纹,这怎么做呢?其实,只要分drawable和drawablev21两个文件夹就好了. 普通情况下的se ...

  6. android自定义控件(4)-自定义水波纹效果

    一.实现单击出现水波纹单圈效果: 照例来说,还是一个自定义控件,观察这个效果,发现应该需要重写onTouchEvent和onDraw方法,通过在onTouchEvent中获取触摸的坐标,然后以这个坐标 ...

  7. CF451A Game With Sticks 水题

    Codeforces Round #258 (Div. 2) Game With Sticks A. Game With Sticks time limit per test 1 second mem ...

  8. HDU4891_The Great Pan_字符串水题

    2014多校第五题,当时题面上的10^5写成105,我们大家都wa了几发,改正后我和一血就差几秒…不能忍 题目:http://acm.hdu.edu.cn/showproblem.php?pid=48 ...

  9. 自定义view实现水波纹效果

    水波纹效果: 1.标准正余弦水波纹: 2.非标准圆形液柱水波纹: 虽说都是水波纹,但两者在实现上差异是比较大的,一个通过正余弦函数模拟水波纹效果,另外一个会运用到图像的混合模式(PorterDuffX ...

随机推荐

  1. HTML+CSS学习

    1.彻底弄懂CSS盒子模式(DIV布局快速入门) 2.在CSS中,BOX的Padding属性的数值赋予顺序为padding:10px; 四个内边距都是10px padding:5px 10px; 上下 ...

  2. Kafka与Logstash的数据采集

    Kafka与Logstash的数据采集 基于Logstash跑通Kafka还是需要注意很多东西,最重要的就是理解Kafka的原理. Logstash工作原理 由于Kafka采用解耦的设计思想,并非原始 ...

  3. css3的loadding效果

    <!DOCTYPE html> <html> <head> <title>CSS3 loading效果</title> <meta c ...

  4. C# 编写服务 Windows service

    1.编写服务教程 http://jingyan.baidu.com/article/ea24bc395e16f8da62b331e7.html 这里不多说了. 给大家一个连接,上面有详细的教程,下面说 ...

  5. 函数fold 或reduce用法

    http://yi-programmer.com/2011-02-24_fold.html http://c2.com/cgi/wiki?FoldFunction http://rwh.readthe ...

  6. 瑞柏匡丞:App对新媒体的影响

    当下App的迅猛发展是媒体进入开放平台时代的折射,作为最具新媒体特质的代表,App充满了社交性与交互性,并有效整合了传统媒体和新媒体的内容和服务.“什么是新媒体”——这个新媒体时代最为核心的命题,实际 ...

  7. python爬虫系列之爬取多页gif图像

                   python爬取多页gif图像 作者:vpoet mail:vpoet_sir@163.com #coding:utf-8 import urllib import ur ...

  8. ssl相关

    http://www.willrey.com/support/ssl_DES.html http://www.07net01.com/linux/Linuxdejiamirenzhenggongnen ...

  9. Vanya and Scales(思维)

    Vanya and Scales time limit per test 1 second memory limit per test 256 megabytes input standard inp ...

  10. Swift中的设计模式

    设计模式(Design Pattern)是 对软件设计中普遍存在的各种问题,所提出的解决方案.这个术语是由埃里希·伽玛等人(Erich Gamma,Richard Helm,Ralph Johnson ...