Red and Black(水)
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
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.
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)
which contains the number of tiles he can reach from the initial tile (including
itself).
#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(水)的更多相关文章
- POJ 1979 Red and Black(水题,递归)
一开始理解错题意了,以为是走过的砖不能再重复走,最多能走多少个黑砖,结果写的递归陷入死循环...后来才明白原来可以重复走,问可以到达的磁砖数. #include <iostream> #i ...
- Android 一个TextView中设置多种不同大小的字体,设置超链接
以前项目中要是遇到这样的UI设计,都是傻不拉唧的分为三个TextView来实现,今天在微信中无意中看了一篇公众号文章,发现原来只要一个TextView就可以搞定啦,人生最悲哀的事情莫过于工作了这么久啦 ...
- poj 1979 Red and Black(dfs水题)
Description There is a rectangular room, covered with square tiles. Each tile is colored either red ...
- Red and Black(dfs水)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1312 Red and Black Time Limit: 2000/1000 MS (Java/Oth ...
- 兼容Android的水波纹效果
Android的水波纹效果只有高版本才有,我们希望自己的应用在低版本用低版本的阴影,高版本用水波纹,这怎么做呢?其实,只要分drawable和drawablev21两个文件夹就好了. 普通情况下的se ...
- android自定义控件(4)-自定义水波纹效果
一.实现单击出现水波纹单圈效果: 照例来说,还是一个自定义控件,观察这个效果,发现应该需要重写onTouchEvent和onDraw方法,通过在onTouchEvent中获取触摸的坐标,然后以这个坐标 ...
- CF451A Game With Sticks 水题
Codeforces Round #258 (Div. 2) Game With Sticks A. Game With Sticks time limit per test 1 second mem ...
- HDU4891_The Great Pan_字符串水题
2014多校第五题,当时题面上的10^5写成105,我们大家都wa了几发,改正后我和一血就差几秒…不能忍 题目:http://acm.hdu.edu.cn/showproblem.php?pid=48 ...
- 自定义view实现水波纹效果
水波纹效果: 1.标准正余弦水波纹: 2.非标准圆形液柱水波纹: 虽说都是水波纹,但两者在实现上差异是比较大的,一个通过正余弦函数模拟水波纹效果,另外一个会运用到图像的混合模式(PorterDuffX ...
随机推荐
- win7 tomcat
前提需要有java环境 cmd 1- 下载tomcat http://tomcat.apache.org/ download Tomcat7.0 2- 配置环境变量 CATALINA_HOME C:\ ...
- shell之rm -rf的别名设置
vim ~/.bashrc alias rm='read -p "Are you ready?" y && [ $y == "y" ] & ...
- postgresql创建用户
(1)内部命令create user 用户名 with superuser password '密码'; 先进入数据库后用命令\h create user 查看帮助 ...
- centos 6.5 安装php redis 扩展
一.安装: 其中,添加PHP扩展需要用到 phpize,所以我们需要安装 php-devel 这个包. #yum install php-devel 然后编译安装phpredis: #git clon ...
- POJ 2417 Discrete Logging
http://www.cnblogs.com/jianglangcaijin/archive/2013/04/26/3045795.html 给p,a,b求a^n==b%p #include<a ...
- IIC的标准操作函数集(C51)包含C和H文件
/********************************************************************* 头文件名 VIIC_C51.H 这个头文件对应的库是VII ...
- 分布式文件系统 fastDFS 安装步骤
安装 fastDFS 很简单. 先安装 libevent, 安装成功后,安装fastDFS. ./make.sh ./make.sh install 我使用一台tracker服务器 192.168. ...
- django项目环境搭建备忘
由于使用python3,所以尽量为每个项目配置虚拟环境来管理各个项目的=. 新建一个项目文件夹,进入该路径 python3 -m venv ll_env 然后激活虚拟环境 source ll_env/ ...
- ALSA音频工具amixer,aplay,arecord
ALSA音频工具编译安装 ========================================================================1.官网http://www. ...
- 点击链接直接跳转到 App Store 指定应用下载页面
//跳转到应用页面 NSString *str = [NSString stringWithFormat:@"http://itunes.apple.com/us/app/id%d" ...