一开始理解错题意了,以为是走过的砖不能再重复走,最多能走多少个黑砖,结果写的递归陷入死循环。。。
后来才明白原来可以重复走,问可以到达的磁砖数。

#include <iostream>
#include <string.h>
#include <stdio.h>
#include <math.h>
#include <algorithm> using namespace std;
int w,h,num,ans;
int f[][];//存储地图的信息,为0代表是黑砖,为1代表红砖,2代表已走过该砖 void search(int row,int col){
if(row<||row>h||col<||col>w){
return;
}
if(f[row][col]==||f[row][col]==)
return;
num++;
f[row][col]=; search(row,col-);
search(row,col+);
search(row-,col);
search(row+,col); }
int main()
{
int px,py;
char str[];
while(scanf("%d%d",&w,&h)!=EOF){
if(w== && h==)
break;
memset(f,,sizeof(f));
num=;
ans=;
for(int i=;i<=h;i++){
scanf("%s",str);
//一开始j从1开始了,囧。。。
for(int j=;j<w;j++){
if(str[j]=='#')
f[i][j+]=;
else if(str[j]=='@'){
//f[i][j]=2;
px=i;
py=j+;
}
}
}
search(px,py);
printf("%d\n",num);
}
return ;
}

POJ 1979 Red and Black(水题,递归)的更多相关文章

  1. POJ 1979 Red and Black (红与黑)

    POJ 1979 Red and Black (红与黑) Time Limit: 1000MS    Memory Limit: 30000K Description 题目描述 There is a ...

  2. poj 3080 Blue Jeans(水题 暴搜)

    题目:http://poj.org/problem?id=3080 水题,暴搜 #include <iostream> #include<cstdio> #include< ...

  3. POJ 3984 - 迷宫问题 - [BFS水题]

    题目链接:http://poj.org/problem?id=3984 Description 定义一个二维数组: int maze[5][5] = { 0, 1, 0, 0, 0, 0, 1, 0, ...

  4. poj 1007:DNA Sorting(水题,字符串逆序数排序)

    DNA Sorting Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 80832   Accepted: 32533 Des ...

  5. poj 1004:Financial Management(水题,求平均数)

    Financial Management Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 126087   Accepted: ...

  6. POJ 3176 Cow Bowling (水题DP)

    题意:给定一个金字塔,第 i 行有 i 个数,从最上面走下来,只能相邻的层数,问你最大的和. 析:真是水题,学过DP的都会,就不说了. 代码如下: #include <cstdio> #i ...

  7. poj 1658 Eva's Problem(水题)

    一.Description Eva的家庭作业里有很多数列填空练习.填空练习的要求是:已知数列的前四项,填出第五项.因为已经知道这些数列只可能是等差或等比数列,她决定写一个程序来完成这些练习. Inpu ...

  8. poj 1979 Red and Black(dfs水题)

    Description There is a rectangular room, covered with square tiles. Each tile is colored either red ...

  9. OpenJudge/Poj 1979 Red and Black / OpenJudge 2816 红与黑

    1.链接地址: http://bailian.openjudge.cn/practice/1979 http://poj.org/problem?id=1979 2.题目: 总时间限制: 1000ms ...

随机推荐

  1. jquery 处理字符串 【转】

    1,去掉空格   var txt=$.trim($("txt1").val()); 2,转为数字   txtNum=Number($.trim(txt)) + 1; var thi ...

  2. c#多层嵌套Json

    Newtonsoft.Json.Net20.dll 下载请访问http://files.cnblogs.com/hualei/Newtonsoft.Json.Net20.rar 在.net 2.0中提 ...

  3. 【Qt】Qt之启动外部程序【转】

    简述 QProcess可以用来启动外部程序,并与它们交互. 要启动一个进程,通过调用start()来进行,参数包含程序的名称和命令行参数,参数作为一个QStringList的单个字符串. 另外,也可以 ...

  4. OS X EI Capitan安装mcrypt

    OS X EI Capitan安装mcrypt   (我的博客原文:http://www.jmolboy.com/2015/12/01/mcrypt-extension-on-EI-Capitan/) ...

  5. php生成圆形图片

    http://files.cnblogs.com/files/adtuu/circle_image.zip

  6. jquery批量控制form禁用的代码

    jquery批量控制form禁用的代码. 代码: <script type="text/javascript" src="/jquery/jquery-1.8.2. ...

  7. Response.Redirect和Server.Transfer

    今天又比较闲,逛了逛园子,看看asp.net的内容,看到一篇关于这两个的比较: http://www.cnblogs.com/yunfeng8967/archive/2008/03/06/109323 ...

  8. C# 使用隐式或显示实现接口的区别

    通俗的来讲,"显示接口实现"就是使用接口名称作为方法名的前缀;而传统的实现方式称之为:"隐式接口实现".费话不说,例子如下:      interface IA ...

  9. [转]null和""以及==与equals的区别

    String str1 = null; str引用为空 String str2 = ""; str引用为空串 直接点就是null没有分配内存空间,而""分配了内 ...

  10. oracle 11g rac 修改字符集

    系统版本: Oracle Linux Server release 5.7 数据库版本: Oracle Database 11g Enterprise Edition Release 11.2.0.3 ...