📣 黑五网一特惠|VIP一年通行证5折,蓝莓、Offer多多同步特惠
楼主: will_ym
跳转到指定楼层
上一主题 下一主题
收起左侧

G onsite 面经 求team match

🔗
huoshankou 2016-1-19 00:18:57 | 只看该作者
全局:
狗家什么时候开始全职都要team match了!
回复

使用道具 举报

🔗
plutoman 2016-1-19 13:59:22 | 只看该作者
全局:
aiwojiujiu 发表于 2016-1-14 20:49
第二轮,这个题目翻译过来就是找从起点到终点的所有路径中,找一条路径,这个路径需要满足的条件是路径上的 ...

非常同意。类似 minimun-spanning-tree 的思路
回复

使用道具 举报

🔗
plutoman 2016-1-19 14:01:59 | 只看该作者
全局:
LYJALEX__ 发表于 2016-1-15 13:36
第二题用个heap就O(n^2 * logn) 了吧? dp复杂度还是很高的要重复扫数组

同意,而且这里的DP的特性只体现在 DAY-TO-DAY, 每一天还是一个DFS/BFS。 但按水位每天变化来做确实不够聪明。
回复

使用道具 举报

🔗
plutoman 2016-1-19 14:15:03 | 只看该作者
全局:
您好!
本帖隐藏的内容需要积分高于 100 才可浏览
您当前积分为 0。
使用VIP即刻解锁阅读权限或查看其他获取积分的方式
游客,您好!
本帖隐藏的内容需要积分高于 100 才可浏览
您当前积分为 0。
VIP即刻解锁阅读权限 或 查看其他获取积分的方式
Unlock interview details and practice with AI
Popular Interview Questions from Top Companies
回复

使用道具 举报

🔗
bobzhang2004 2016-1-24 11:41:12 | 只看该作者
全局:
aiwojiujiu 发表于 2016-1-14 20:49
第二轮,这个题目翻译过来就是找从起点到终点的所有路径中,找一条路径,这个路径需要满足的条件是路径上的 ...

那楼主所说的dp做是什么意思呢?
回复

使用道具 举报

🔗
bobzhang2004 2016-1-24 11:52:45 | 只看该作者
全局:
根据aiwojiujiu的思路写了下代码
  1. public class MinimumDaysToReachDestination {
  2.         class Cell {
  3.                 public int x, y, h;

  4.                 Cell() {
  5.                 }

  6.                 Cell(int xx, int yy, int hh) {
  7.                         x = xx;
  8.                         y = yy;
  9.                         h = hh;
  10.                 }
  11.         }

  12.         class CellComparator implements Comparator<Cell> {
  13.                 public int compare(Cell x, Cell y) {
  14.                         if (x.h > y.h) {
  15.                                 return 1;
  16.                         } else if (x.h == y.h) {
  17.                                 return 0;
  18.                         } else {
  19.                                 return -1;
  20.                         }
  21.                 }
  22.         }

  23.         int[] dx = { 1, -1, 0, 0 };
  24.         int[] dy = { 0, 0, 1, -1 };

  25.         public int getMinimumDaysToReachDestination(int[][] heights) {
  26.                 // write your code here
  27.                 if (heights == null || heights.length == 0 || heights[0].length == 0) {
  28.                         return 0;
  29.                 }
  30.                 PriorityQueue<Cell> q = new PriorityQueue<Cell>(11,
  31.                                 new CellComparator());
  32.                 int n = heights.length;
  33.                 int m = heights[0].length;
  34.                 boolean[][] visited = new boolean[n][m];
  35.                 q.offer(new Cell(0, 0, heights[0][0]));
  36.                 visited[0][0] = true;
  37.                 int ans = Integer.MIN_VALUE;
  38.                 while (!q.isEmpty()) {
  39.                         Cell now = q.poll();
  40.                         ans = Math.max(ans, heights[now.x][now.y]);
  41.                         if (now.x == n - 1 && now.y == m - 1) {
  42.                                 return ans;
  43.                         }
  44.                         for (int i = 0; i < 4; i++) {
  45.                                 int nx = now.x + dx[i];
  46.                                 int ny = now.y + dy[i];
  47.                                 if (0 <= nx && nx < n && 0 <= ny && ny < m && !visited[nx][ny]) {
  48.                                         visited[nx][ny] = true;
  49.                                         q.offer(new Cell(nx, ny, Math.max(now.h, heights[nx][ny])));
  50.                                 }
  51.                         }
  52.                 }
  53.                 return ans == Integer.MIN_VALUE? Integer.MAX_VALUE : ans;
  54.         }
  55.        
  56.        
  57.         public static void main(String[] args) {
  58.                 int[][] matrix = {{1, 2},
  59.                         {3, 4}};
  60.                 int[][] matrix2 = {{1, 3, 5},
  61.                                                    {6, 10, 9},
  62.                                                    {4, 3, 2}};
  63.                 MinimumDaysToReachDestination m = new MinimumDaysToReachDestination();
  64.                 System.out.println(m.getMinimumDaysToReachDestination(matrix));
  65.                 System.out.println(m.getMinimumDaysToReachDestination(matrix2));
  66.         }
  67. }
复制代码
回复

使用道具 举报

🔗
aiwojiujiu 2016-1-24 11:54:05 | 只看该作者
全局:
bobzhang2004 发表于 2016-1-24 11:41
那楼主所说的dp做是什么意思呢?

楼主想多了
回复

使用道具 举报

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

本版积分规则

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