深搜,向四个方向,在不越界的情况下一直闷头走,直到撞墙。到达终点就输出,没到就回溯。

 #include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
using namespace std;
int n,m;
int map[][];
int xxx,yyy;
int ans=;
int tx[]={,-,,};
int ty[]={,,,-};
void dfs(int x,int y,int step)
{
if(step>=ans||step>=)
{
return;
}
for(int i=;i<;i++)
{
int sx=x+tx[i];
int sy=y+ty[i];
if(map[sx][sy]==)continue;
while(sx>=&&sy>=&&sx<n&&sy<m&&map[sx][sy]!=&&map[sx][sy]!=)
{
sx+=tx[i];
sy+=ty[i];
}
if(sx<||sy<||sx==n||sy==m)continue;
else
{
if(map[sx][sy]==)
{
ans=step+;
return;
}
else
{
map[sx][sy]=;
dfs(sx-tx[i],sy-ty[i],step+);
map[sx][sy]=;
}
}
}
}
int main()
{
while(cin>>m>>n&&n!=&&m!=)
{
ans=;
for(int i=;i<n;i++)
{
for(int j=;j<m;j++)
{
cin>>map[i][j];
if(map[i][j]==)
{
xxx=i;
yyy=j;
}
}
}
dfs(xxx,yyy,);
if(ans==) cout<<-<<endl;
else cout<<ans<<endl;
}
}
请各位大佬斧正(反正我不认识斧正是什么意思)

POJ P3009 Curling 2.0 题解的更多相关文章

  1. poj 3009 Curling 2.0 (dfs )

    Curling 2.0 Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 11879   Accepted: 5028 Desc ...

  2. POJ 3009 Curling 2.0 {深度优先搜索}

    原题 $On Planet MM-21, after their Olympic games this year, curling is getting popular. But the rules ...

  3. POJ 3009 Curling 2.0【带回溯DFS】

    POJ 3009 题意: 给出一个w*h的地图,其中0代表空地,1代表障碍物,2代表起点,3代表终点,每次行动可以走多个方格,每次只能向附近一格不是障碍物的方向行动,直到碰到障碍物才停下来,此时障碍物 ...

  4. poj 3009 Curling 2.0

    题目来源:http://poj.org/problem?id=3009 一道深搜题目,与一般搜索不同的是,目标得一直往一个方向走,直到出界或者遇到阻碍才换方向. 1 #include<iostr ...

  5. POJ 3009 Curling 2.0(DFS + 模拟)

    题目链接:http://poj.org/problem?id=3009 题意: 题目很复杂,直接抽象化解释了.给你一个w * h的矩形格子,其中有包含一个数字“2”和一个数字“3”,剩下的格子由“0” ...

  6. POJ 3009 Curling 2.0 回溯,dfs 难度:0

    http://poj.org/problem?id=3009 如果目前起点紧挨着终点,可以直接向终点滚(终点不算障碍) #include <cstdio> #include <cst ...

  7. poj 3009 Curling 2.0( dfs )

    题目:http://poj.org/problem?id=3009 参考博客:http://www.cnblogs.com/LK1994/ #include <iostream> #inc ...

  8. 【POJ】3009 Curling 2.0 ——DFS

    Curling 2.0 Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 11432   Accepted: 4831 Desc ...

  9. POJ 3009:Curling 2.0 推箱子

    Curling 2.0 Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 14090   Accepted: 5887 Desc ...

随机推荐

  1. 【Python爬虫案例学习】分析Ajax请求并抓取今日头条街拍图片

    1.抓取索引页内容 利用requests请求目标站点,得到索引网页HTML代码,返回结果. from urllib.parse import urlencode from requests.excep ...

  2. STC单片机Flash做EEPROM的代码

    STC官方给出的建议: /***************************************************************Author:Liming*** * @brie ...

  3. Etcd 使用入门

    etcd简介 etcd是CoreOS团队于2013年6月发起的开源项目,它的目标是构建一个高可用的分布式键值(key-value)数据库.etcd内部采用raft协议作为一致性算法,etcd基于Go语 ...

  4. ElasticSearch监控工具 - cerebro

    官方地址:https://github.com/lmenezes/cerebro 需要有java环境 下载地址:https://github.com/lmenezes/cerebro/releases ...

  5. Drools 规则文件语法概述

    概述(Overview) 以.drl为扩展名的文件,是Drools中的规则文件,规则文件的编写,遵循Drools规则语法.下面详细介绍一下Drools规则文件语法.具体参考官方文档: https:// ...

  6. easy ui 弹框叠加问题

    1.框架用的是.net MVC,Index页面如下所示: @{ Layout = "~/Views/Shared/_CustomerLayout.cshtml"; ViewBag. ...

  7. 表单提交学习笔记(三)—利用Request.Files上传图片并预览

    一.html页面如下 <div id="container"> <form id="myForm"> <p class=" ...

  8. MVC Filter的使用方法

    相信对权限过滤大家伙都不陌生 用户要访问一个页面时 先对其权限进行判断并进行相应的处理动作 在webform中 最直接也是最原始的办法就是 在page_load事件中所有代码之前 先执行一个权限判断的 ...

  9. spark-sql使用笔记

    如何使用hive的udf 可以使用spark-sql --jars /opt/hive/udf.jar,指定udf的路径 还可以在spark-default.conf里指定spark.jars /op ...

  10. Javascript处理数组的方法

    一 迭代方法 ES5为数组定义了5个迭代方法,这些方法大大方便了处理数组的任务,支持这些方法的浏览器有 IE9+,Firefox2+,Safari3+,Opera9.5+和Chrome. 1 ever ...