12
返回列表 发新帖
楼主: 匿名
跳转到指定楼层
上一主题 下一主题
收起左侧

骨骼VO 面经

🔗
djmiss 2021-6-8 06:45:14 | 只看该作者
全局:
第四题竟然还有人考。。。好像2-3年前的高频了吧
回复

使用道具 举报

全局:
有谁能讲一下第四题生成迷宫的code或者李扣上的类似题目么??谢谢!!!
回复

使用道具 举报

地里匿名用户
🔗
匿名用户-UBZIG  2021-6-19 15:01:04
本帖最后由 匿名 于 2021-6-19 15:02 编辑
Katherineaa1223 发表于 2021-6-19 13:45
有谁能讲一下第四题生成迷宫的code或者李扣上的类似题目么??谢谢!!!
[i]
  1. int[][] DIR = new int[][] {
  2.         {-1, 0},
  3.         {0, 1},
  4.         {0, -1},
  5.         {1, 0}
  6. };       
  7. public int[][] mazeGenerator(int height, int width, int[] start, int[] end) {
  8.         int[][] maze = new int[height][width];
  9.         List<int[]> path = new ArrayList<>();
  10.         dfs(start[0], start[1], end, visited, path);
  11.         Random random = new Random();
  12.         for(int[] point : path) {
  13.                 maze[point[0]][point[1]] = 1;
  14.         }
  15.         for(int i = 0; i < height; ++i) {
  16.                 for(int j = 0; j < width; ++j) {
  17.                         if(maze[i][j] == 1) continue;
  18.                         maze[i][j] = random.nextInt(2);
  19.                 }
  20.         }
  21.         return maze;
  22. }

  23. private boolean dfs(int h, int w, int[] end, boolean[][] visited, List<int[]> path) {
  24.         if(h < 0 || h == visited.length || w < 0 || w == visited[0].length || visited[h][w]) return false;
  25.         visited[h][w] = true;
  26.         path.add(new int[]{h, w});
  27.         if(h == end[0] && w == end[1]) return true;
  28.         for(int[] dir : DIR) {
  29.                 if(dfs(maze, h + dir[0], w + dir[1], end, visited, path)) return true;
  30.         }
  31.         visited[h][w] = false;
  32.         path.remove(path.size() - 1);
  33.         return false;
  34. }

  35. /*
  36.         Followup:
  37.         其实就是每次把dfs内部用来存放移动方向的DIR在每次call dfs的时候shuffle下.
  38.         具体实现随意.
  39. */
复制代码

[/i]

评分

参与人数 2大米 +5 收起 理由
CeliaYa + 2 很有用的信息!
bearxiong2017 + 3 很有用的信息!

查看全部评分

回复

使用道具 举报

地里匿名用户
🔗
匿名用户-6PCIC  2021-8-18 13:01:18
很有用的信息,感谢你的分享!

评分

参与人数 2大米 +5 收起 理由
cannoli + 2 赞一个!
ykwwind + 3 给你点个赞!

查看全部评分

回复

使用道具 举报

地里匿名用户
🔗
匿名用户-NRPLH  2021-8-18 22:52:49 来自APP
答的都很好,想不通挂在哪里?
回复

使用道具 举报

地里匿名用户
🔗
匿名用户-UBZIG  2021-8-18 23:02:53 来自APP
匿名用户 发表于 2021-08-18 07:52:49
答的都很好,想不通挂在哪里?
不知啊…
但是手上别的pkg都比看到的狗L4大……
(微笑)
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册账号
隐私提醒:
  • ☑ 禁止发布广告,拉群,贴个人联系方式:找人请去🔗同学同事飞友,拉群请去🔗拉群结伴,广告请去🔗跳蚤市场,和 🔗租房广告|找室友
  • ☑ 论坛内容在发帖 30 分钟内可以编辑,过后则不能删帖。为防止被骚扰甚至人肉,不要公开留微信等联系方式,如有需求请以论坛私信方式发送。
  • ☑ 干货版块可免费使用 🔗超级匿名:面经(美国面经、中国面经、数科面经、PM面经),抖包袱(美国、中国)和录取汇报、定位选校版
  • ☑ 查阅全站 🔗各种匿名方法

本版积分规则

>
快速回复 返回顶部 返回列表