java算法(三十九)

1、给定一个用数字表示的迷宫矩阵,其中-2是入口,-3是出口,-1是障碍物,0表示道路,>0的表示传送门,处于传送门的位置可以像道路一样从上下左右走,相比道路传送门可以一步就传送到另外一个传送门的位置。比如上面的例子:第一行的1可以直接跳到行末的1。

输入:

4 3

1 0 -1 1

-2 0 -1 -3

2 2 0 0

输出:

3

代码如下:

package com.cc.demo;

import java.util.*;

public class test024 {
    /**
     * test:
     4 3
     1 0 -1 1
     -2 0 -1 -3
     2 2 0 0
     */

    // 存储位置
    static class Pos{
        int x;
        int y;
        public Pos(int x, int y) {
            this.x = x;
            this.y = y;
        }
    }
    private static final int INF = 2000*2000;
    // 下,上,右,左
    private static int[][] move = new int[][]{
 {0,1}, {0,-1}, {1,0}, {-1,0}};
    private static Map<Integer, ArrayList<Pos>> map;

    public static void main(String[] args) {
        // 这是我自己封装的读矩阵的函数,会先读入行和列,再按照行和列读入矩阵
        // 在写笔试的时候可以把一些经常用到的读取函数提前写好,
        // 可以节省很多处理输入的时间(写笔试的一点小Trick)
        int[][] matrix = readMatrix(true);
        for(int i=0; i<matrix.length; i++){
            for(int j=0; j<matrix[0].length; j++){
                System.out.print(matrix[i][j]+" ");
            }
            System.out.println();
        }
        map = new 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值