题意:

从左上角跳到右下角最少需要多少步,跳的规则为:可以向四个方向的任意一个方向跳当前格子中的步数,若跳不到右下角输出IMPOSSIBLE。

题解:

BFS搜索,注意判断边界,标记。

代码:

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <stdio.h>
#include <cmath>
#include <cstring>
#include <vector>
#include <map>
#include <set>
#include <bitset>
#include <queue>
#include <cstdlib>
#include <utility>
using namespace std;
#define is_lower(c) (c>='a' && c<='z')
#define is_upper(c) (c>='A' && c<='Z')
#define is_alpha(c) (is_lower(c) || is_upper(c))
#define is_digit(c) (c>='0' && c<='9')
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define IO ios::sync_with_stdio(0);\
    cin.tie();\
    cout.tie();
#define For(i,a,b) for(int i = a; i <= b; i++)
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<int,int > pll;
typedef vector<int> vi;
const ll inf=0x3f3f3f3f;
;
const ll inf_ll=(ll)1e18;
const ll maxn=100005LL;
const ll mod=1000000007LL;
+;
pair <int,int> p;
queue <pii> q;
int mp[N][N];
int xx[N][N];
bool vis[N][N];
int main() {
    int m,n;
    cin >> m >> n;
    For(i,,m)
        For(j,,n)
            scanf("%1d",&mp[i][j]);
    p.first = ;p.second = ;
    q.push(p);
    vis[][] = ;
    ;
    while(!q.empty()){
        pii x = q.front();
        q.pop();
        int step = mp[x.first][x.second];
        pii x1;
        &&(x.first+step)<=m&&!vis[x.first+step][x.second]){
            x1.first = x.first+step,x1.second = x.second;
            q.push(x1);
            xx[x1.first][x1.second] = xx[x.first][x.second]+;
            vis[x1.first][x1.second] = ;
        }//向下
        &&(x.first-step)<=m&&!vis[x.first-step][x.second]){
            x1.first = x.first-step,x1.second = x.second;
            q.push(x1);
            xx[x1.first][x1.second] = xx[x.first][x.second]+;
            vis[x1.first][x1.second] = ;
        }// up
        &&(x.second+step)<=n&&!vis[x.first][x.second+step]){
            x1.first = x.first,x1.second = x.second+step;
            q.push(x1);
            xx[x1.first][x1.second] = xx[x.first][x.second]+;
            vis[x1.first][x1.second] = ;
        }
        &&(x.second-step)<=n&&!vis[x.first][x.second-step]){
            x1.first = x.first,x1.second = x.second-step;
            q.push(x1);
            xx[x1.first][x1.second] = xx[x.first][x.second]+;
            vis[x1.first][x1.second] = ;
        }
        )
            break;
    }
    )
        cout << xx[m][n] <<endl;
    else
        cout <<"IMPOSSIBLE" << endl;
    ;
}

最新文章

  1. ASP.NET MVC5----了解我们使用的@HTML帮助类
  2. HttpSession与Hibernate中Session的区别
  3. 修改.gitignore后让其生效
  4. java Thread和Runnable区别
  5. Oracle10G 连接11G数据库,出现ORA -1017用户名/口令无效; 登录被拒绝 的问题
  6. uchome 积分体系
  7. Sharpdevelop使用StyleCop
  8. 转载:Struts2+Jquery实现ajax并返回json类型数据
  9. HDU 3468 BFS+二分匹配
  10. oracle查询每个表所占的空间
  11. Scrapy爬虫框架补充内容一(Linux环境)
  12. mysql 悲观锁与乐观锁的理解
  13. C#使用WebClient下载文件到本地目录
  14. 【XSY2701】异或图 线性基 容斥原理
  15. 一个基于netty的websocket聊天demo
  16. python标准库介绍——2 os.path模块详解
  17. android how to deal with data when listview refresh
  18. ubuntu 关闭触控板
  19. vue.js学习笔记(二)——vue-router详解
  20. 协议(Protocol)与委托代理(Delegate)

热门文章

  1. Ubuntu修改系统语言为英文可支持中文
  2. [freemarker篇]01.入门Freemarker示例
  3. MSSQL Export Excel
  4. mybatis在Mapper的xml文件中的转义字符的处理
  5. centos6.8+openvpn实现账户密码连接(通过端口映射的方式)
  6. asp.net RDLC报表入门
  7. GitLab 迁移与升级
  8. 深入理解微服务架构spring的各个知识点(面试必问知识点)
  9. John&#39;s trip(POJ1041+欧拉回路+打印路径)
  10. 铺砖问题 (状态压缩dp)