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. Spring HibernateTemplate的使用

    Spring HibernateTemplate的使用 2008-03-25 11:38 2020人阅读 评论(0) 收藏 举报 springbeanhibernatesessiondaoclass ...

  2. Eclipse 安装使用 Maven

    安装 Maven 下载 Maven  http://mirrors.hust.edu.cn/apache/maven/maven-3/3.3.9/binaries/apache-maven-3.3.9 ...

  3. 一次oracle大量数据删除经历

    oracle有个数据表现在已经有2500万条数据了,软件用到这个表的数据时就变的特别慢,所以准备把一个月以前的数据全部清除. 我的步骤是(下边操作都是在plsql中运行的) 1.首先 将这个月的数据导 ...

  4. Excel导出cs文件

    using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.UI ...

  5. 使用PHP从web访问mysql数据库

    一. web数据库构架的工作原理 1. 用户由浏览器发出HTTP请求,请求特定的web页面. 2. web服务器接受接收到对特定页面的请求,检索相应文件,并将其传递给php引擎处理. 3. php引擎 ...

  6. WPF & ArcGIS Engine三维开发入门攻略

    原文 http://www.cnblogs.com/Realh/archive/2010/12/14/1906112.html 前些日子在做ESRI的开发大赛,从刚开始接触ArcGIS Engine( ...

  7. POJ 1195 Mobile phones (二维树状数组或线段树)

    偶然发现这题还没A掉............速速解决了............. 树状数组和线段树比较下,线段树是在是太冗余了,以后能用树状数组还是尽量用......... #include < ...

  8. 用来控制 XML 序列化的属性

    通过将下表中的属性应用于类和类成员,可以控制 XmlSerializer 序列化或反序列化该类的实例的方式.若要了解这些属性如何控制 XML 序列化,请参见使用属性控制 XML 序列化. 这些属性还可 ...

  9. STL中,迭代器的分类

    五类迭代器如下: 1.输入迭代器:只读,一次传递    为输入迭代器预定义实现只有istream_iterator和istreambuf_iterator,用于从一个输入流istream中读取.一个输 ...

  10. 从设计模式说起JAVA I/O流

    从设计模式说起JAVA I/O流 之前写过一篇I/O流的入门介绍,直到最近看了设计模式,顺带理下I/O流的设计思路. JAVA类库中的I/O类分成输入和输出两部分,通过继承,任何自InputStrea ...