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 ...
随机推荐
- php计算时间差的方法
一个简单的例子:计算借书的天数,根据每天的日期进行计算. (1) 有数据库的情况 MSSQL可以使用触发器!用专门计算日期差的函数datediff()便可. MYSQL那就用两个日期字 ...
- android.support.v7.app.AppCompatActivity
1.Android Studio (api 23) 新建项目的时候 Activity public class MainActivity extends AppCompatActivity 2.系统默 ...
- DemoExample
<HTML> <HEAD> <TITLE>使用递归求解斐波那契数列</TITLE> </HEAD> <BODY> <?ph ...
- EXTJS 4.2 资料 控件之Window窗体自动填充页面
1.html页面代码: <div id="component" style="width:100%;height:100%"> <body&g ...
- Xcode常用设置
1.设置主题和字体大小 2.设置显示代码行号
- 洛谷 P1858 多人背包
求01背包前k优解的价值和 输入输出格式 Input/output 输入格式:第一行三个数K.V.N(k<=50,v<=5000,n<=200)接下来每行两个数,表示体积和价值输出格 ...
- 子查询注意这几点, 就可以写出好的sql语句
执行sql时子查询的语句一般优先执行 理论上多表查询效率是高于子查询(根据子查询不值一个查询语句可能会有多个from但是多表查询只产生一个from), 但是在oracle中子查询效率一般会高于多表查询
- Hadoop1.0.3集成eclipse开发
本文来自:http://www.ilablog.org/%E7%BC%96%E8%AF%91hadoop-eclipse%E6%8F%92%E4%BB%B6/ 本人由于工作原因目前没有亲自尝试,那位尝 ...
- WCF入门教程一[什么是WCF]--转载只为学习收藏
一.概述 Windows Communication Foundation(WCF)是由微软发展的一组数据通信的应用程序开发接口,可以翻译为Windows通讯接口,它是.NET框架的一部分.由 .NE ...
- CROSS APPLY vs OUTER APPLY
Apply 工作原理: Apply操作符让符合查询的每一条记录都调用一次TVF函数,并将结果与原数据表的记录内容一起展开. Apply操作符定义在From子句内,使用方式与Join操作符类 ...