#include <stdio.h>
int H,L;
int qx,qy,zx,zy;
int map[21][21];
int ax[4]={-1,0,1,0};
int ay[4]={0,-1,0,1};

void dfs(int x , int y , int step)
{
	if(step>10)
	{
		return ;
	}
	int tx,ty;
	for(int i=0;i<4;i++)
	{
		if(map[x+ax[i]][y+ay[i]]==0)
		{
			tx=x+ax[i];
			ty=y+ay[i];
			while(map[tx][ty]==0)
			{
				tx=tx+ax[i];
				ty=ty+ay[i];

			}
		}
	}
}
void main()
{
	freopen("in.txt","r",stdin);
	while(1)
	{
		scanf("%d %d",&L,&H);
		if(L==0&&H==0)
			break;
		for(int i=0;i<H;i++)
		{
			for(int j=0;j<L;j++)
			{
				scanf("%d",&map[i][j]);
				if(map[i][j]==2)
				{
					qx=i;
					qy=j;
					map[i][j]=0;
				}
				if(map[i][j]==3)
				{
					zx=i;
					zy=j;
				}
			}
		}

		dfs(qx,qy,0);

	}
}

poj3009的更多相关文章

  1. POJ3009——Curling 2.0(DFS)

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

  2. poj3009 Curling 2.0(很好的题 DFS)

    https://vjudge.net/problem/POJ-3009 做完这道题,感觉自己对dfs的理解应该又深刻了. 1.一般来说最小步数都用bfs求,但是这题因为状态记录很麻烦,所以可以用dfs ...

  3. POJ-3009 Curling 2.0 (DFS)

    Description On Planet MM-21, after their Olympic games this year, curling is getting popular. But th ...

  4. 《挑战程序设计竞赛》2.1 深度优先搜索 POJ2386 POJ1979 AOJ0118 AOJ0033 POJ3009

    POJ2386 Lake Counting Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 25366   Accepted: ...

  5. POJ-3009 Curling 2.0---DFS求最短路

    题目链接: https://vjudge.net/problem/POJ-3009 题目大意: 问题:打冰球.冰球可以往上下左右4个方向走,只有当冰球撞到墙时才会停下来,而墙会消失.当冰球紧贴墙时,不 ...

  6. POJ3009 Curling

    题目链接:http://poj.org/problem?id=3009 题意:从2出发,要到达3, 0可以通过,碰到1要停止,并且1处要变成0, 并且从起点开始沿着一个方向要一直前进,直至碰到1(或者 ...

  7. POJ3009 Curling 2.0

    正式做POJ的第一题,做出来后又看了别人的代码,就又完善了一下,也通过了.参考 http://blog.sina.com.cn/s/blog_4abcd9bc0100phzb.html 改了之后觉得写 ...

  8. POJ3009 Curling 2.0(DFS)

    题目链接. 分析: 本题BFS A不了. 00100 00001 01020 00000 00010 00010 00010 00010 00030 对于这样的数据,本来应当是 5 步,但bfs却 4 ...

  9. POJ3009:Curling 2.0(dfs)

    http://poj.org/problem?id=3009 Description On Planet MM-21, after their Olympic games this year, cur ...

随机推荐

  1. Linux下apache+phppgadmin+postgresql安装配置

    Linux下apache+phppgadmin+postgresql安装配置 操作系统:CentOS 安装包:httpd(首选yum), php(包括php以及php-pgsql,php-mbstri ...

  2. 第六百一十二、三、四、五天 how can I 坚持

    上火了啊..已经2017了,真快,人生只是一瞬间,到头来都是一场空. 2016年最后一天,很悲催,没赶上火车.还不能改签,哪能哪次都这么幸运,长记性了,下午到济南,看了看弟弟的房子,到挺不错,就是装修 ...

  3. Ubuntu 14.10安装SecureCRT 7.3(转)

    原文 :http://blog.csdn.net/chszs/article/details/40623169 1.软件准备 Ubuntu14.04 x64 下载SecureCRT7.3的版本:scr ...

  4. 关于JDK 安装,以及Java环境的设置

    关于JDK 安装,以及Java环境的设置 1.下载JDK1.6,选择对应的安装路径 2.配置相应的Java 环境变量 A.属性名称:JAVA_HOME 属性值:C:\Program Files\Jav ...

  5. 使用php技术实现无刷新的上传文件

  6. Delphi2010 DataSnap入门

    DataSnap到了Delphi2010有了很大的变化,已经可以完全抛弃DCOM之类的东西了,在以前版本中建立一个DataSnap,需要使用DCOMConnection或者SockConnection ...

  7. windbg命令----!idt

    !idt扩展显示指定的中断分配表(interrupt dispatch table (IDT))中的中断服务例程(interrupt service routine (ISR)) -a 没有指定IDT ...

  8. asp.net GDI+绘制五边形

    using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.We ...

  9. JSP(include指令与<jsp:include>动作的区别)

    <%@ page language= "java" contentType="text/html;charset=UTF-8" %><html ...

  10. Ubuntu如何更新源

    Ubuntu的源其实就是更新各种软件包需要用到镜像网站, 当大家在虚拟机上安装Linux镜像的时候肯定会遇到各种Linux软件没有安装,当你用apt-get安装的时候它会提示无效的网址,这个时候你就需 ...