POJ 3009
来源:互联网 发布:mac os 终端命令 编辑:程序博客网 时间:2024/06/06 05:52
#include<iostream>#include<cstdio>using namespace std;int Map[30][30];int dir[4][2]= {{1,0},{-1,0},{0,1},{0,-1}};int ans;int n,m;int sx,sy;void dfs(int x,int y,int sum){ if(sum>=10)return; for(int i=0;i<4;i++){ int tx=x+dir[i][0]; int ty=y+dir[i][1]; if(Map[tx][ty]==1)continue; while(!Map[tx][ty]){ tx+=dir[i][0]; ty+=dir[i][1]; } if(tx<0||tx>n-1||ty<0||ty>m-1)continue; if(Map[tx][ty]==1){ Map[tx][ty]=0; dfs(tx-dir[i][0],ty-dir[i][1],sum+1); Map[tx][ty]=1; } if(Map[tx][ty]==3){ ans=min(ans,sum+1); } }}int main(){ while(scanf("%d%d",&m,&n)!=EOF&&(n&&m)) { for(int i=0; i<n; i++) for(int j=0; j<m; j++) { scanf("%d",&Map[i][j]); if(Map[i][j]==2) { sx=i; sy=j; Map[i][j]=0; } } ans=11; dfs(sx,sy,0); if(ans<11) printf("%d\n",ans); else printf("-1\n"); } return 0;}
阅读全文
0 0
- POJ 3009
- poj 3009
- POJ 3009
- POJ 3009
- POJ-3009
- POJ 3009
- POJ 3009
- poj-3009
- poj--3009
- poj 3009
- POJ 3009
- poj-3009
- poj 3009
- POJ 3009
- poj 3009
- 【POJ】3009
- POJ 3009
- poj 3009
- ASP.NET 事务处理
- hello
- 判断是否有网,判断网络连接,跳转至设置
- Linux命令(1)-cat & 反向tac
- mabatis学习之前今日内容介绍 1、final 关键字 2、static 关键字 3、匿名对象 4、内部类 5、包的声明与访问 6、访问修饰符 7、代码块 第一节课 ###01(面向对象)fin
- POJ 3009
- 2.1.5 自定义view
- Ajax和PHP
- 题目:有一分数序列:2/1,3/2,5/3,8/5,13/8,21/13...求出这个数列的前 20 项之和
- SSL2828 2017年11月2日提高组T1 Sequence(kmp)
- 字符串编码(腾讯笔试)
- 关于maven项目导入本地项目生成jar包,一直提示找不到类的处理方法
- bzoj 2109: [Noi2010]Plane 航空管制 贪心+拓扑排序
- Servlet过滤器