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 ...
随机推荐
- WeX5是主要进行app开发吗?能开发微信App吗?
WeX5是一款html5开发工具,可以进行app开发,做出各种H5 App,同样也可以进行主要运行在PC的html5产品,. WeX5开发的应用,不仅可以在微信上运行,也可以直接手机浏览器运行,或者打 ...
- Keep two divs sync scroll and example
srcDiv has visible horizontal scrollbar.(style="overflow:auto;") targetDiv has no scrollba ...
- webpack+react+jquery和jquery插件
要引入jquery插件 全局引入jquery plugins : [new webpack.ProvidePlugin({ $: 'jquery', jQuery:'jquery' "win ...
- Linux学习1
Linux中一切皆文件,且不依靠扩展名区分文件,学习Linux必须要熟悉在字符界面进行文件的管理. 首先是Linux的查询命令. (1)ls -a是显示当前目录所有文件,包含隐藏文件,如图中文件名前加 ...
- Sugarcrm Email Integration
Introdurce http://www.sugarcrm.com/feature/email-integration Tutor http://www.youtube.com/watch?v=BQ ...
- linux whereis which
whereis 命令只能用于程序名的搜索,而且只搜索二进制文件(参数-b).man说明文件(参数-m)和源代码文件(参数-s). [root@localhost ~]# whereis svn svn ...
- Qt单元测试
单元测试之作用要完成测试用例,保证设计上的耦合依赖通过测试用例,保证覆盖率,提高程序质量 QTest一些有用的静态函数QTest::qExecQTest::qSleepQTest::qWait 例 ...
- ios app - 打开系统设置URL
ios --- 调用系统"设置"里的功能(转) 安装后第一次运行软件时,系统会弹出提示用户是否允许软件获取当前位置,如果用户不允许的话,之后运行时系统不会在弹出提示设置,这点很不方 ...
- 简单3d RPG游戏 之 004 攻击(二)
人物和怪物的攻击都有CD冷却,在PlayerAttack脚本中添加成员 //冷却倒计时 public float attackTimer; //CD冷却时间 public float coolDown ...
- JS中遍历普通数组和字典数组的区别
// 普通数组 var intArray = new Array(); intArray[0] = "第一个"; intArray[1] = "第二个"; fo ...