poj 3009 Curling 2.0( dfs )
题目: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 )的更多相关文章
- POJ 3009 Curling 2.0(DFS + 模拟)
题目链接:http://poj.org/problem?id=3009 题意: 题目很复杂,直接抽象化解释了.给你一个w * h的矩形格子,其中有包含一个数字“2”和一个数字“3”,剩下的格子由“0” ...
- POJ 3009 Curling 2.0【带回溯DFS】
POJ 3009 题意: 给出一个w*h的地图,其中0代表空地,1代表障碍物,2代表起点,3代表终点,每次行动可以走多个方格,每次只能向附近一格不是障碍物的方向行动,直到碰到障碍物才停下来,此时障碍物 ...
- poj 3009 Curling 2.0 (dfs )
Curling 2.0 Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 11879 Accepted: 5028 Desc ...
- 【POJ】3009 Curling 2.0 ——DFS
Curling 2.0 Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 11432 Accepted: 4831 Desc ...
- POJ 3009 Curling 2.0 {深度优先搜索}
原题 $On Planet MM-21, after their Olympic games this year, curling is getting popular. But the rules ...
- POJ 3009 Curling 2.0 回溯,dfs 难度:0
http://poj.org/problem?id=3009 如果目前起点紧挨着终点,可以直接向终点滚(终点不算障碍) #include <cstdio> #include <cst ...
- poj 3009 Curling 2.0
题目来源:http://poj.org/problem?id=3009 一道深搜题目,与一般搜索不同的是,目标得一直往一个方向走,直到出界或者遇到阻碍才换方向. 1 #include<iostr ...
- 【原创】poj ----- 3009 curling 2 解题报告
题目地址: http://poj.org/problem?id=3009 题目内容: Curling 2.0 Time Limit: 1000MS Memory Limit: 65536K Tot ...
- POJ3009——Curling 2.0(DFS)
Curling 2.0 DescriptionOn Planet MM-21, after their Olympic games this year, curling is getting popu ...
随机推荐
- Object-C - 类的定义
http://www.cnblogs.com/zhangweia/archive/2011/11/01/2231549.html 1. 文件分为.h:定义接口,及其属性,方法说明. .m :是实现类. ...
- js字符串长度计算(一个汉字==两个字符)和字符串截取
js字符串长度计算(一个汉字==两个字符)和字符串截取 String.prototype.realLength = function() { return this.replace(/[^\x00-\ ...
- Laravel框架数据库CURD操作、连贯操作总结
这篇文章主要介绍了Laravel框架数据库CURD操作.连贯操作.链式操作总结,本文包含大量数据库操作常用方法,需要的朋友可以参考下 一.Selects 检索表中的所有行 复制代码代码如下: $use ...
- JavaScript 高级程序设计 02-变量、数据类型
一.JavaScript变量 1.变量的定义 在定义变量时,统一使用关键字var,后跟变量名(即标识符,如果不知道什么是标识符,可以到这去查看),如下 var message; //定义一个变量 注意 ...
- 6个好用的Web开发工具
在过去的几年间,涌现出了很多Web开发工具,它们大多还是比较吸引人的,方便了我们的工作.我们可以学习一下这些新东西,短时间就可以拓宽思路(PHP100推荐:学习10分钟,改变你的程序员生涯).这些应用 ...
- delphi 自带报告内存泄漏
//报告内存泄漏 ReportMemoryLeaksOnShutdown := true;
- 2014年辛星完全解读Javascript第七节 数组和对象
由于Javascript是脚本语言,因此,使用起来非常方便,数组的使用也是比较简单的,下面我们就主要介绍一下Javascript中数组的介绍,以及上一节中没有完成的对象的介绍. *********** ...
- asp.net mvc Ajax.BeginForm不能异步刷新,或转到新页面,或页面还是刷新了,的原因(或解决办法)(转)
昨天搞了一下午的Ajax.BeginForm都没能实现异步刷新,一直将返回的数据提交到新的页面,在网上搜了n多方法都不行,问了n多人都没能搞定,今天大一早,就意外的被我发现了问题所在. 布局页: &l ...
- mvc简单execl导出
直接上代码: public static byte[] GetExecl(DataTable dt, List<string> list) { var sbHtml = new Strin ...
- Mysql异常:MySQLNonTransientConnectionException: No operations allowed after statement closed
Mysql异常:MySQLNonTransientConnectionException: No operations allowed after statement closed MySQLNonT ...