Red and Black
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.
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)
set, your program should output a line which contains the number of
tiles he can reach from the initial tile (including
itself).
0ms)
#include
#include
#include
#define maxn 100
using namespace std;
bool visit[maxn][maxn];
char mapn[maxn][maxn];
int direction[4][2]={{1,0},{0,1},{-1,0},{0,-1}};
int w,h,s=1;
void dfs(int w,int h,int sx,int sy)
{
int
x,y;
for(int
i=0;i<4;i++)
{
//printf("i=%d\n",i);
x=sx+direction[i][0];
y=sy+direction[i][1];//记录坐标
if(x>=1&&x<=h&&y>=1&&y<=w&&visit[x][y]==false&&mapn[x][y]=='.')
{
visit[x][y]=true;
s++;
dfs(w,h,x,y);
}
}
}
int main()
{
//freopen("in.txt", "r", stdin);
int
x,y;
while(~scanf("%d%d\n",&w,&h)&&(w||h))
{
//printf("w=%d h=%d\n",w,h);
s=1;
memset(visit,false,sizeof(visit));
for(int i=1;i<=h;i++)
{
for(int j=1;j<=w;j++)
{
scanf("%c",&mapn[i][j]);
// printf("mapn[i][j]=%c\n",mapn[i][j]);
//printf("i=%d\n",i);
if(mapn[i][j]=='@')
{
x=i;
y=j;
visit[x][y]=true;
}//记录@符出现的位置
}
scanf("\n");
}
//for(int i=1;i<=h;i++)
//{
// for(int
j=1;j<=w;j++)
// {
//
printf("%c",mapn[i][j]);
// }
// printf("\n");
//}
//printf("mapn[x][y]=%c\n",mapn[x][y]);
dfs(w,h,x,y);//开始深搜
printf("%d\n",s);
}
return
0;
}
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 ...
随机推荐
- 在github上实现页面托管预览功能
1.建立个人github pages 仓库 创建新仓库,命名规则为----"你的github账号.github.io", 如图所示: 我的账号是zxpsuper,所以我的个人域名仓 ...
- 【转】独立游戏如何对接STEAM SDK
独立开发者在对接STEAM SDK之前 首先得先登上青睐之光,也就是我们俗称的"绿光" 一般要先对接G胖家的SDK,然后提交版本,最后等待审核... 我本身是unity 开发,对C ...
- jmeter测试教程
http://www.cnblogs.com/TankXiao/p/4045439.html
- 修改Form ->Top和Left 造成的莫名其妙的显示异常 “轴信息”
相关代码: 运行程序: 要等待很久,或者把主窗体最小化,再最大化打开"轴信息" 才会恢复正常. 这个"不爽"很蛋蛋 ,网友亲亲们,有独到见解的亲亲们,期待得到你 ...
- 组合 Lucas定理
组合 Time Limit: 1000MS Memory Limit: 32768KB 64bit IO Format: %I64d & %I64u [Submit] [Go Ba ...
- YYModel学习总结YYClassInfo(1)
OC的run-time 机制,简直像是网络上的猫! 我在开发中很少用到,但是作为iOS开发 人家肯定会问这个东西,所以深入的学习了下. 对于 run-time的入手,YYModel的学习,简直让人美滋 ...
- 【MVC】MvcPager分页及边界传递数据示例
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.We ...
- Linux基础命令讲解(二)
Linux命令基本格式: 命令 [参数] [路径文件] 方括号内容可省略 查看命令帮助手段: 1 man 命令名 (man 还可以获取配置文件,函数的帮助) 2 命令 --help 3 help 命令 ...
- #云栖大会# 移动安全专场——APP渠道推广作弊攻防那些事儿(演讲速记)
导语: 如今,移动互联网浪潮进入白热化竞争态势,APP渠道传播成为很多企业常用的推广方式,APP推广费用也在水涨船高,从PC时代的一个装机0.5元到1元不等,到移动互联网时代的5元,甚至几十元,但为什 ...
- ABAP 动态内表 动态ALV
DATA: DY_TABLE TYPE REF TO DATA, DY_WA TYPE REF TO DATA. FIELD-SYMBOLS: <DYN_TABLE> TYPE TABLE ...