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 ...
随机推荐
- laravel扩展图片处理Intervention Image
github地址:https://github.com/Intervention/image
- ECshop sina
http://blog.sina.com.cn/s/blog_5327408801019ofa.html http://blog.sina.com.cn/u/2624360105 http://blo ...
- Nodejs & Mongod
http://cwbuecheler.com/web/tutorials/2013/node-express-mongo/
- 【转】 Linux Core Dump 介绍
=============================================================== Linux core dump的祥细介绍和使用 =========== ...
- docker下PHP+Nginx+HHVM运行环境
Dockerfile 准备开始,我们创建一个 Dockerfile —— Dockerfile 包含如何创建所需镜像的指令. FROM centos:centos6MAINTAINER Mike ...
- (转)《深入理解java虚拟机》学习笔记9——并发编程(一)
随着多核CPU的高速发展,为了充分利用硬件的计算资源,操作系统的并发多任务功能正变得越来越重要,但是CPU在进行计算时,还需要从内存读取输出,并将计算结果存放到内存中,然而由于CPU的运算速度比内存高 ...
- UITableViewCell 重合问题解决方法
这两天做ios遇到一个UITableViewCell 数据重合的问题,原因:引起这个问题的主要原因是,重用cell.之前cell上的内容未被清空,而又增加新增内容所致.从网上查了一些解决方法,比如: ...
- 【学习总结】OS X , IOS , IOS SDK , XCode之间的关系
几个基本的概念 : OS X : 属于桌面PC级别(IMac,MacPro等)对应安装的操作系统 IOS : 属于移动设备级别(Iphone,Ipad等)对应安装的操作系统 XCode: 是一个IDE ...
- 如何循环遍历document.querySelectorAll()方法返回的结果
使用JavaScript的forEach方法,我们可以轻松的循环一个数组,但如果你认为document.querySelectorAll()方法返回的应该是个数组,而使用forEach循环它: /* ...
- 快速配置Ehcache
1. 编写ehcache.xml文件,将该文件放置于classpath路径下.代码如下: <?xml version="1.0" encoding="UTF-8&q ...