tw无人机路线规划代码

很多私信都问过这个问题 今天清理idea里的代码
分享一下 然后清理了
问题描述:
一个字符型二维矩阵中,每个格子都代表一个地理位置信息,需要设计一个无人机的飞行路线,拍下地图全景,每次可以拍上下左右中五个位置的照片。
主要思路:
1 螺旋飞行+3格定时拍照,每三个格子拍照一次,可以保证拍下全图。足够大的情况下,拍照次数约为全图1/3
2 隔行跳跃飞行,可以保证拍下全图。足够大的情况下,飞行距离约为全图1/3
代码很简单,思路也很简单,这一面一般不会挂人,最后挂在了非技术上也是挺离谱

import java.util.Scanner;

public class Plane {

    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        int row = input.nextInt();
        int col = input.nextInt();
        // 创建地图
        int[][] map = createMap(row, col);
        // 螺旋飞行
        //new SolutionOne().spiralTravel(map, 0, map[0].length - 1, 0, map.length - 1);
        // 跳跃飞行
        new SolutionTwo().skipTravel(map, 0, map[0].length - 1, 1, map.length - 1);
        // 打印结果
        printMap(map);
    }

    private static int[][] createMap(int row, int col) {
        return new int[row][col];
    }

    private static void printMap(int[][] map) {
        for (int[] info : map) {
            for (int val : info) {
                System.out.print(val + " ");
            }
            System.out.println();
        }
    }
}

public class SolutionOne {

    public void spiralTravel(int[][] map, int left, int right, int up, int down) {
        int count = 0;
        while (true) {
            // 左到右
            for (int col = left; col <= right; col++) {
                takePhoto(map, up, col, count++);
            }
            if (++up > down) break;
            // 上到下
            for (int row = up; row <= down; row++) {
                takePhoto(map, row, right, count++);
            }
            if (--right < left) break;
            // 右到左
            for (int col = right; col >= left; col--) {
                takePhoto(map, down, col, count++);
            }
            if (--down < up) break;
            // 下到上
            for (int row = down; row >= up; row--) {
                takePhoto(map, row, left, count++);
            }
            if (++left > right) break;
        }
    }

    private void takePhoto(int[][] map, int row, int col, int count) {
        if (count % 3 == 0) {
            map[row][col] = 1;
        }
    }
}
public class SolutionTwo {

    public void skipTravel(int[][] map, int left, int right, int up, int down) {
        boolean leftToRight = true;
        while (true) {
            if (leftToRight) {
                moveL2R(map, left, right, up);
                leftToRight = false;
            } else {
                moveR2L(map, left, right, up);
                leftToRight = true;
            }
            // 边界判断
            if (up + 1 == down) {
                break;
            }
            // 跳跃条件
            if (up + 3 < down) {
                up = leftToRight ? skip(map, up, left, 3) : skip(map, up, right, 3);
            } else if (up + 3 == down) {
                up = leftToRight ? skip(map, up, left, 2) : skip(map, up, right, 2);
            } else {
                up = leftToRight ? skip(map, up, left, 1) : skip(map, up, right, 1);
            }
        }
    }

    private int skip(int[][] map, int up, int direction, int count) {
        for (int i = 0; i < count; i++) {
            map[up++][direction] = 1;
        }
        return up;
    }


    private void moveL2R(int[][] map, int left, int right, int up) {
        for (int col = left; col <= right; col++) {
            map[up][col] = 1;
        }
    }

    private void moveR2L(int[][] map, int left, int right, int up) {
        for (int col = right; col >= left; col--) {
            map[up][col] = 1;
        }
    }
}
#Thoughtworks#
全部评论
大佬牛逼 顺便贴个当时写的博客,xdm参考下,献丑啦 https://shitsurei.online/droneCrossPhotograph.html
15 回复
分享
发布于 2020-10-22 15:09
考了好几年了 不知道明年会不会继续
1 回复
分享
发布于 2020-10-21 09:11
英特尔
校招火热招聘中
官网直投
话说方案陈述阶段会要求英文陈述吗
1 回复
分享
发布于 2020-10-23 19:47
 tw好像一直是这个题
点赞 回复
分享
发布于 2020-10-21 14:58
今年tw都没了么···我感觉我测评做的挺好的,也没收到要做题的消息
点赞 回复
分享
发布于 2020-10-21 20:28
老无人机了 印象里都考三年了吧?
点赞 回复
分享
发布于 2020-10-21 20:29
想问下,c++技术栈的面试这个公司是不是凉了
点赞 回复
分享
发布于 2020-10-22 11:00
我实习投递做这个,正式投递还是这个。。。
点赞 回复
分享
发布于 2020-10-22 19:22
牛。不过刚考完才看到有点惨
点赞 回复
分享
发布于 2020-10-23 19:47
求问楼主方案陈述的时候要讲代码吗
点赞 回复
分享
发布于 2020-10-24 12:29
后面群面也离谱,不知道公司想要什么样的人😂
点赞 回复
分享
发布于 2020-10-24 12:48
请问楼主,无人机笔试及面试、群面、笔试之后,还有几个面啊?焦急😫
点赞 回复
分享
发布于 2020-10-29 15:52
感谢分享😘
点赞 回复
分享
发布于 2020-11-19 15:29
** 我当时写了个BFS。。。。原来是模拟么
点赞 回复
分享
发布于 2020-11-23 17:22
楼主什么岗位啊
点赞 回复
分享
发布于 2020-11-26 13:54
补录给我发的文件是购物车程序,估计要换题了😂
点赞 回复
分享
发布于 2021-01-15 10:32
边界判断和条件判断哪里看不懂,能解释下吗,拜托了
点赞 回复
分享
发布于 2021-10-15 17:05

相关推荐

20 227 评论
分享
牛客网
牛客企业服务