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

#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. 返璞归真vc++之字符类型

    在今天,大量使用java与.net的程序员已经很少去真实了解字符的底层表达,但是使用VC++编程,对字符的处理却非常慎重,刚学习vc++肯定会为其中的字符类型给晕头转向,今天本人学习第一节,从字符开始 ...

  2. git 终端常输入命令

    cd 输入命令 ls 返回目录 git add . 相当于保存代码 git commit -m "" 相当于提交 get pull把服务器上代码拉回本地代码. get pust 刷 ...

  3. iOS ARC基本原理

    一.ARC基本简介 ARC:Automatic Reference Counting 自动引用 完全消除了手动管理内存的烦琐,编译器会自动在适当的地方插入适当的retain.release.autor ...

  4. 这是html5中WebGL的演示

    这是html5中WebGL的演示,让我们与他人分享爱您发送短消息.每次你进入它使用不同的位置,新的爱情点被添加到全球.让世界更明亮的地方与你的朋友分享! 源文件:部分代码:<!DOCTYPE h ...

  5. linux命令行解析函数介绍

    函数原型:         int getopt(int argc,char * const argv[ ],const char * optstring);         给定了命令参数的数量 ( ...

  6. 解决nginx负载均衡的session共享问题

    1.不使用session,换用cookie session是存放在服务器端的,cookie是存放在客户端的,我们可以把用户访问页面产生的session放到cookie里面,就是以cookie为中转站. ...

  7. js中隐式类型转换测试

    javascript数据类型: 使用typeof可以返回的数据类型有六种 "number" , "string" ,  "boolean" ...

  8. jQuery基础选择器

    attr()方法的功能是设置或获取元素的某项属性值. attr("disabled", "true”)表示使该功能不可用. #id 选择器 $("#my_id& ...

  9. Mysql 正则获取字段的交集【转】

    问题描述 比如table1中有两条记录 name no a    2,9 b    8,10 然后有一串字符串,是0,1,2,3,4 然后通过一条sql,找出no为2,9的记录来``` 因为字符串中有 ...

  10. Oracle 动态视图2 V$LOCKED_OBJECT

    v$locked_object视图列出当前系统中哪些对象正被锁定 Column Datatype Description XIDUSN NUMBER 回滚段号 XIDSLOT NUMBER 槽号 XI ...