解救公主游戏

import java.util.*;

public class U2407p26 {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int s = sc.nextInt();
        List<String> ss = new ArrayList<>();
        String step = "";
        int a = 0;
        while(s>a){
            a++;
            String temp = sc.next();
            step = step.concat(temp);
            ss.add(temp);
        }
        int f = 50/s;
        int y = 50%s;
        List<String> ss2 = new ArrayList<>();
        while (f > 0){
            ss2.add(step);
            f--;
        }
        if (y != 0){
            String ll = "";
            for (int t = 0; t < y;t++){
                ll = ll.concat(ss.get(t));
            }
            ss2.add(ll);
        }
        int[][] start = new int[][]{{0,0}};
        String direction = "北";
        Map<Integer,int[][]> map = new HashMap<>();
        char[] chars = step.toCharArray();
        int m =0;
        for(int j = 0 ; j < ss2.size()*4;j++){
            for (int i = 0; i < step.length(); i++){
                if(chars[i] == 'S'){
                    m++;
                    switch (direction){
                        case "北":{
                            int[][] locate = new int[][]{{0,1}};
                            start = getLocate(start,locate);
                            map.put(m,locate);
                            break;
                        }
                        case "东":{
                            int[][] locate = new int[][]{{1,0}};
                            start = getLocate(start,locate);
                            map.put(m,locate);
                            break;
                        }
                        case "南":{
                            int[][] locate = new int[][]{{0,-1}};
                            start = getLocate(start,locate);
                            map.put(m,locate);
                            break;
                        }
                        case "西":{
                            int[][] locate = new int[][]{{-1,0}};
                            start = getLocate(start,locate);
                            map.put(m,locate);
                            break;
                        }
                    }
                }
                if(chars[i] == 'L'){
                    for (int ii = 0; ii < 4; ii++){
                        if (direction == "北"){
                            direction = "西";
                            break;
                        }
                        if (direction == "西"){
                            direction = "南";
                            break;
                        }
                        if (direction == "南"){
                            direction = "东";
                            break;
                        }
                        if (direction == "东"){
                            direction = "北";
                            break;
                        }
                    }
                }
                if(chars[i] == 'R'){
                    for (int ii = 0; ii < 4; ii++){
                        if (direction == "北"){
                            direction = "东";
                            break;
                        }
                        if (direction == "东"){
                            direction = "南";
                            break;
                        }
                        if (direction == "南"){
                            direction = "西";
                            break;
                        }
                        if (direction == "西"){
                            direction = "北";
                            break;
                        }
                    }
                }
            }
            if (start[0][0] == 0 && start[0][1] == 0 ){
                System.out.println("bounded");
                return;
            }
        }
        if (start[0][0] != 0 || start[0][1] != 0 ){
            System.out.println("unbounded");
        }else{
            System.out.println("bounded");
        }
    }

    private  static int[][] getLocate(int[][] source, int[][] dest){
       return new int[][]{{dest[0][0] + source[0][0],dest[0][1] + source[0][1]}};
    }

}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值