Red and Black
Red and Black
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 6865 Accepted Submission(s): 4359
Write a program to count the number of black tiles which he can reach by repeating the moves described above.
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)
....#.
.....#
......
......
......
......
......
#@...#
.#..#.
11 9
.#.........
.#.#######.
.#.#.....#.
.#.#.###.#.
.#.#..@#.#.
.#.#####.#.
.#.......#.
.#########.
...........
11 6
..#..#..#..
..#..#..#..
..#..#..###
..#..#..#@.
..#..#..#..
..#..#..#..
7 7
..#.#..
..#.#..
###.###
...@...
###.###
..#.#..
..#.#..
0 0
59
6
13
#include<stdio.h>
#include<string.h>
char str[][];
int temp[][];
int cnt,h,w;
void dfs(int x,int y)
{
cnt ++;
temp[x][y] =;
if(!temp[x+][y]&& x+ < w)
dfs(x+,y);
if(!temp[x-][y] && x- > -)
dfs(x-,y);
if(!temp[x][y+] && y+ < h)
dfs(x,y+);
if(!temp[x][y-] && y- > -)
dfs(x,y-);
} int main()
{
int i,j,a,b;
while(~scanf("%d%d",&h,&w)&&h+w)
{
cnt =;
for(i =;i < w;i ++)
{
scanf("%s",str[i]);
for(j =;j < h;j ++)
{
if(str[i][j] == '#')
temp[i][j] =;
if(str[i][j] == '.')
temp[i][j] =;
if(str[i][j] == '@')
{
a = i;
b = j;
}
}
}
dfs(a,b);
printf("%d\n",cnt);
}
return;
}
Red and Black的更多相关文章
- 使用Red Gate Sql Data Compare 数据库同步工具进行SQL Server的两个数据库的数据比较、同步
Sql Data Compare 是比较两个数据库的数据是否相同.生成同步sql的工具. 这一款工具由Red Gate公司出品,我们熟悉的.NET Reflector就是这个公司推出的,它的SQLTo ...
- 使用Red Gate Sql Compare 数据库同步工具进行SQL Server的两个数据库的结构比较、同步
将测试版的项目同步(部署)到正式版的时候,两个数据库的结构比较与同步时,如果修改数据库的时候没有记录好修改了那些表,很难将两个数据库进行同步 RedGate Sql Compare使用简介说明: 1. ...
- 新年抢红包效果(New Year Red Packet)
新年抢红包效果(New Year Red Packet) 晓娜的文章(微信公众号:migufe) 2016即将过去,我们将迎来新的一年2017,这里小编提前祝大家新年快乐!万事如意!那我们新年最开心的 ...
- KALI Linux problems & Study Red Hat | Ubuntu
Problem When you ask some website with https head.you may met the problem secure connection failed ...
- Red Gate(SQLToolbelt)SQL Server的安装与注册(破解)
Red Gate(SQLToolbelt)是SQL Server辅佐工具 1.SQL Compare 比较和同步SQL Server数据库结构 2.SQL Data Compare 比较和同步SQL ...
- Red Hat Enterprise Server 6.0 安装Sendmail相关包
由于需要在Linux服务器(Red Hat Enterprise Linux Server release 6.0)上配置邮件服务,需要安装Sendmail包,一般Sendmail的安装有两种方式:R ...
- Red Hat Enterprise Linux 6.6安装体验
Red Hat Enterprise Linux 6.6的安装首界面有五个选项,这跟以前的Red Hat Enterprise Linux 5.x的安装界面是有一些区别的. 安装或者升级现有系统( ...
- Red Hat Enterprise Linux 各个版本以及发布日期
Red Hat Enterprise Linux 7 Release/Update General Availability Date redhat-release Errata Date* Kern ...
- linux red hat 给普通用户开启root权限
环境:虚拟机:red hat 6.5:root角色用户:普通用户:宏基笔记本:win7: 操作过程: 1.登录普通用户,进入图形界面(可以设置为启动登录进入命令行界面): 2.按Crl+ALT+F2进 ...
- 【BZOJ-1419】Red is good 概率期望DP
1419: Red is good Time Limit: 10 Sec Memory Limit: 64 MBSubmit: 660 Solved: 257[Submit][Status][Di ...
随机推荐
- asp:时间的计算
DataTime dt = new DataTime();//dt为时间DataTime对象 dt.ToString();//2005-11-5 13:47:04 dt.AddYears(1).ToS ...
- mongodb下载及安装配置教程【仅供参考】
1 下载 下载页面地址:https://www.mongodb.org/downloads 版本选择:电脑系统是64位的,所以我选择了 Windows 64-bit 2008 R2+ ,msi包 2 ...
- 设计模式之 Factory Method 工厂方法
看到的比较有意思的一篇描述工厂方法的文章. http://www.codeproject.com/Articles/492900/From-No-Factory-to-Factory-Method 总 ...
- 深度优化LNMP之Nginx [2]
深度优化LNMP之Nginx [2] 配置Nginx gzip 压缩实现性能优化 1.Nginx gzip压缩功能介绍 Nginx gzuo压缩模块提供了压缩文件内容的功能,用户请求 ...
- linux/win7下安装websphere application server
说明: 1.参考网址:http://www.ibm.com/developerworks/cn/aix/library/au-wasonlinux/ 2.在ibm官网上下载websphere appl ...
- 关于ubuntu上执行错误命令报错
Sorry, command-not-found has crashed! 新安装了一台ubuntu server 安装时用中文安装的,之后命令行下各种乱码,最后也不知道是修改哪里造成的 每次执行一次 ...
- a标签使用
1.发起邮件 注意:如果mailto后面同时有多个参数的话,第一个参数必须以“?”开头,后面的参数每一个都以“&”分隔. <a href="mailto:281345774@q ...
- css按钮自适应
原理:利用a标签和i标签各自一个背景组合成为按钮,达到自适应. <!DOCTYPE html> <html> <head> <meta charset=&qu ...
- html5写的一个时钟
看到的一个html5写的时钟 <!doctype> <html> <head> <script> window.onload=function(){ v ...
- FusionCharts xml入门教程
由于项目需求需要做一个报表,选择FusionCharts作为工具使用.由于以 前没有接触过报表,网上也没有比较详细的fusionCharts教程,所以决定好好研究FusionCharts,同时做一个比 ...