A - Red and Black(3.2.1)(搜索)
Time Limit:1000MS Memory Limit:30000KB 64bit IO Format:%I64d
& %I64u
cid=1008#status//A/0" class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only" style="font-family:Verdana,Arial,sans-serif; font-size:1em; border:1px solid rgb(211,211,211); background-color:rgb(227,228,248); color:rgb(85,85,85); display:inline-block; position:relative; padding:0px; margin-right:0.1em; zoom:1; overflow:visible; text-decoration:none">Status
Description
Write a program to count the number of black tiles which he can reach by repeating the moves described above.
Input
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)
The end of the input is indicated by a line consisting of two zeros.
Output
Sample Input
6 9
....#.
.....#
......
......
......
......
......
#@...#
.#..#.
11 9
.#.........
.#.#######.
.#.#.....#.
.#.#.###.#.
.#.#..@#.#.
.#.#####.#.
.#.......#.
.#########.
...........
11 6
..#..#..#..
..#..#..#..
..#..#..###
..#..#..#@.
..#..#..#..
..#..#..#..
7 7
..#.#..
..#.#..
###.###
...@...
###.###
..#.#..
..#.#..
0 0
Sample Output
45
59
6
13
#include<iostream>
#include<cstring>
using namespace std;
int b,c,k,i,s,x,y,n;
char a[21][21];
int sousuo(int x,int y,int a1,int b)
{
int n=0;
if(x>0)
if(a[x-1][y]=='.')
{n++;a[x-1][y]='a';n=n+sousuo(x-1,y,a1,b);}
if(y>0)
if(a[x][y-1]=='.')
{n++;a[x][y-1]='a';n=n+sousuo(x,y-1,a1,b);}
if(x<a1)
if(a[x+1][y]=='.')
{n++;a[x+1][y]='a';n=n+sousuo(x+1,y,a1,b);}
if(y<b)
if(a[x][y+1]=='.')
{n++;a[x][y+1]='a';n=n+sousuo(x,y+1,a1,b);}
return n;
}
int main()
{
int j;
while(cin>>k>>s&&k)
{
memset(a,'q',sizeof(a));
for(i=0;i<s;i++)
for(j=0;j<k;j++)
{
cin>>a[i][j];
if(a[i][j]=='@')
x=i,y=j;
} n=sousuo(x,y,s,k);
cout<<++n<<endl;
}
return 0;
}
A - Red and Black(3.2.1)(搜索)的更多相关文章
- POJ 1979 Red and Black 四方向棋盘搜索
Red and Black Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 50913 Accepted: 27001 D ...
- [Vim] 搜索模式(正则表达式)
本文介绍如何使用Vim的搜索模式. 搜索单词 Vim中使用 \< 和 \> 分别表示单词的开头和结尾,例如查找单词 i 而不是字母 i ,在正常模式下,按下 / 启动搜索模式,输入 \&l ...
- Windows App开发之集成设置、帮助、搜索和共享
应用设置和应用帮助 "设置"合约 上一节中我们学习了怎样将应用设置保存到本地.这样的方式是通过在App内加入设置选项,这里另一种方式. 微软将其称为"设置"合约 ...
- laravel7 jqAjax下拉框搜索
html: 设置页面改变事件 <div id="show"> <div class="page-container" style=" ...
- solr教程
转载请注明出处:http://www.cnblogs.com/zhuxiaojie/p/5764680.html 本教程基于solr5.5 前言 至于为什么要用solr5.5,因为最新的6.10,没有 ...
- div+css实现各种形状(精心整理)
1.正方形.div {width: 100px;height: 100px;background: red;} 2.矩形.div {width: 200px;height: 100px;backgro ...
- Linux共享库、静态库、动态库详解
1. 介绍 使用GNU的工具我们如何在Linux下创建自己的程序函数库?一个“程序函数库”简单的说就是一个文件包含了一些编译好的代码和数据,这些编译好的代码和数据可以在事后供其他的程序使用.程序函数库 ...
- Elasticsearch Search APIs
Elasticsearch Search APIs By:授客 QQ:1033553122 1. 搜索 1 在单个索引的所有类型中搜索 1 在单个索引的指定类型中搜索 1 在多个指定的索引中搜索 1 ...
- 安装 Zsh 及 Oh-my-zsh
详细介绍就略过吧,可以参考这篇文章:使用ZSH的九个理由 下面记录一下我在配置ZSH的过程中的要点: 1.基本上你能找到的配置教程都是基于oh-my-zsh的. 因为zsh配置过于复杂,所以有了oh- ...
- PHP实现openSug.js参数调试
这是一款利PHP对百度搜索下拉框提示免费代码实现参数配置调试的程序源代码. 由想要对网站进行搜索下拉调试的站长朋友们进行方便.快速的效果演示,具体参考下面的PHP代码. 如何使用? 请新建一份PHP文 ...
随机推荐
- MySQL安装for windows
======MySQL安装 for windows====== 版本5.7.X MySQL服务器帮助我们来管理文件的操作 MySQL软件 - 服务器端软件 - 服务端程序 - 解析指令 - 对文件的操 ...
- BZOJ 4517 组合数+错排
思路: 预处理错排 然后C(n,m)*s[n-m-1]就是答案了 特判n-m-1<0 //By SiriusRen #include <cstdio> using namespace ...
- POJ 3468 线段树+状压
题意:给你n个数,有对区间的加减操作,问某个区间的和是多少. 思路:状压+线段树(要用lazy标记,否则会TLE) //By SiriusRen #include <cstdio> #in ...
- ASP.NET的Eval方法和Bind方法的区别
Eval是只读的方法(单向数据在邦定),所邦定的内容为不会提交回服务器. 比如图书的ISBN,并不想让用户做任何修改,可以使用<%# Eval('ISBN').TOString().Trim() ...
- Oracle 循环调用存储过程
create or replace procedure p_test_loop as --定义一个游标,并将查询结果集赋值给它 CURSOR c1 IS select * from tbltest w ...
- 解决无法移除tomcat中的项目
问题:启动myeclipse,tomcat提示报错,blind,但是你移除的时候无法移除,只会显示一个黄色的感叹号,此时你直接在webapp中删除时,也提示呗占用无法删除. 办法:关掉myeclips ...
- Deutsch lernen (14)
1. das Abseits, - 越位 Der Linienrichter winkte Abseits. winken - winkte - gewunken 示意 2. abs ...
- Assembly之instruction之Register Mode
Assembler Code Content of ROM MOV R10,R11 MOV R10,R11 Length: One or two words Operation: Move the c ...
- (转)基于MVC4+EasyUI的Web开发框架经验总结(10)--在Web界面上实现数据的导入和导出
http://www.cnblogs.com/wuhuacong/p/3873498.html 数据的导入导出,在很多系统里面都比较常见,这个导入导出的操作,在Winform里面比较容易实现,我曾经在 ...
- vue.js的ajax和jsonp请求
首先要声明使用ajax 在 router下边的 Index.js中 import VueResource from 'vue-resource'; Vue.use(VueResource); ajax ...