题目:http://poj.org/problem?id=3009

参考博客:http://www.cnblogs.com/LK1994/

 #include <iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<stack>
#include<queue>
#include<iomanip>
#include<cmath>
#include<map>
#include<vector>
#include<algorithm>
using namespace std; int w,h,G[][];
int d[][]={{,},{,-},{-,},{,}};
int minstep; int dfs(int sx,int sy,int step)
{
if(step>)
return step;
for(int i=; i<; i++)
for(int k=; k<; k++)
{
int tx=sx+d[i][]*k;
int ty=sy+d[i][]*k;
if(tx>=&&tx<=h&&ty>=&&ty<=w)
{
if(G[tx][ty]==) return step+;
else if(G[tx][ty]==)
{
if(k==) break;
int x=sx+d[i][]*(k-);
int y=sy+d[i][]*(k-);
G[tx][ty]=;
minstep=min(minstep,dfs(x,y,step+));
G[tx][ty]=;
break;
}
}
else break;
}
return minstep;
}
int main()
{
int sx,sy,ans;
while(cin>>w>>h&&(w!=||h!=))
{
for(int i=; i<=h; i++)
for(int j=; j<=w; j++)
{
cin>>G[i][j];
if(G[i][j]==)
{
sx=i; sy=j;
G[i][j]=;
}
}
minstep=;
ans=dfs(sx,sy,);
if(ans>) ans=-;
cout<<ans<<endl;
}
return ;
}

poj 3009 Curling 2.0( dfs )的更多相关文章

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

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

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

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

  3. poj 3009 Curling 2.0 (dfs )

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

  4. 【POJ】3009 Curling 2.0 ——DFS

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

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

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

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

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

  7. poj 3009 Curling 2.0

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

  8. 【原创】poj ----- 3009 curling 2 解题报告

    题目地址: http://poj.org/problem?id=3009 题目内容: Curling 2.0 Time Limit: 1000MS   Memory Limit: 65536K Tot ...

  9. POJ3009——Curling 2.0(DFS)

    Curling 2.0 DescriptionOn Planet MM-21, after their Olympic games this year, curling is getting popu ...

随机推荐

  1. jQuery scroll(滚动)延迟加载

    延迟加载 $(window).scroll(function(){ var scrollHeight = $(document).height(); //文档高度 var scrollTop = $( ...

  2. html5 的<audio> 音频 audio的“坑”

    <audio>标签是html5的一个非常有意义的特性.告别的flash的时代.它的属性有: autoplay:音频就绪后马上播放 controls:出现该属性,向用户显示播放的控件. lo ...

  3. WPF ListBox的DataTemplate例子

    <ListBox Name="lbLogInfo"> <ListBox.ItemTemplate> <DataTemplate> <Gri ...

  4. .vimrc & .bashrc 文件配置

    /* 如果vim还没有语法高亮,那么在/etc/profile 中添加以下语句 */ export TERM=xterm-color // 注: 只对各个用户自己的主目录下的.vimrc修改的话,修改 ...

  5. CLR.via.C#第三版 读书笔记

    第一章 CLR的执行模型 1.1将源代码编译成托管代码 决定将.NET Framework作为自己的开发平台之后,第一步是决定要生成什么类型的应用程序或组件.假定你已经完成了这些次要的细节:一切都已经 ...

  6. 【BZOJ 2440】[中山市选2011]完全平方数

    Description 小 X 自幼就很喜欢数.但奇怪的是,他十分讨厌完全平方数.他觉得这些数看起来很令人难受.由此,他也讨厌所有是完全平方数的正整数倍的数.然而这丝毫不影响他对其他数的热爱. 这天是 ...

  7. Mapped Statements collection does not contain value for ResearcherMapper.方法名

    搞了半天, 原来是映射文件没加, 新手常遇到的问题. Mapped Statements collection does not contain value for后面是什么类什么方法之类的: 错误原 ...

  8. c#3位一分(money)

     NumberFormatInfo num = new NumberFormatInfo();         num.NumberDecimalDigits = 2;         string ...

  9. ORA-12514 TNS 监听程序当前无法识别连接描述符中请求服务 的解决方法

    今天用PL/SQL连接虚拟机中的Oracle数据库,发现报了“ORA-12514 TNS 监听程序当前无法识别连接描述符中请求服务”错误,也许你也遇到过,原因如下: oracle安装成功后,一直未停止 ...

  10. 微软Hololens设备 浅分析

    微软Hololens的定位是一款MR 设备(Mixed reality).MR与AR的不同我认为是MR能够将真实环境的场景信息与虚拟对象进行完美的融合,它是基于SLAM(SimultaneousLoc ...