📣 VIP通行证夏日特惠 限时立减$68
楼主: 匿名
跳转到指定楼层
上一主题 下一主题
收起左侧

狗家 匹村 现场面 面经

🔗
江渚散人 2018-9-23 05:15:24 | 只看该作者
全局:
第一题是不是一个国人大叔。我也是。我觉得我的解法当时是对的。但是不知道会给我什么feedback
回复

使用道具 举报

🔗
yunsan9999 2018-9-23 10:24:48 | 只看该作者
全局:
第四道题不是很easy,至少从代码量上来说
回复

使用道具 举报

🔗
anyarok 2018-9-23 15:54:03 | 只看该作者
全局:
lz google只面算法吗,其他的会有吗,像ood, system design
回复

使用道具 举报

🔗
deeper99 2018-9-23 16:08:17 | 只看该作者
全局:
论坛匿名用户 发表于 2018-9-23 04:50
修机器的人每次修一列的时候,只能走到最右边再往下,或是原路返回从最左边往下,这个是面试官的要求,在 ...

如果是你这样的提议我感觉就是dp的解法,dp[i][0]代表着是从左边走到这一行的,dp[i][1]代表着从右边往下走到这一行的,转移方程也很容易写
回复

使用道具 举报

🔗
chuqianyiding 2018-9-23 23:57:30 | 只看该作者
全局:
论坛匿名用户 发表于 2018-9-23 04:50
修机器的人每次修一列的时候,只能走到最右边再往下,或是原路返回从最左边往下,这个是面试官的要求,在 ...

那这样的话就是bfs了, 当y == 0 的时候可以向右 或者向下, 当y == col-1的时候可以向左或者向下,
当0<y<col的时候,保持原有的方向,但是当修复了坏机器,这时可以选择转向或者继续前进,
我代码的问题是我没有找到好的保存状态的办法,我既要保存位置,还有已经修复的机器,还有前进的方向,
我自己都觉得写的代码很恶

public List<int[]> ShortestPathFixMachine(int row, int col, List<int[]> machines)
        {
            HashSet<int> machineSet = new HashSet<int>();
            foreach (int[] a in machines)
            {
                machineSet.Add(a[0] * col + a[1]);
            }

            int n = machines.Count;
            Queue<Tuple<int, string,int>> queue = new Queue<Tuple<int, string,int>>();
            HashSet<Tuple<int, string,int>> visited = new HashSet<Tuple<int, string,int>>();
            if (machineSet.Contains(0))
            {
                Tuple<int, string,int> t = new Tuple<int, string,int>(0, "0",1);
                queue.Enqueue(t);
                visited.Add(t);
            }
            else
            {
                Tuple<int, string,int> t = new Tuple<int, string,int>(0, "",1);
                queue.Enqueue(t);
                visited.Add(t);

            }
            
            while (queue.Count > 0)
            {               
                Tuple<int, string,int> cur = queue.Dequeue();
               
                string[] arr = cur.Item2.Split(',');
                if (arr.Length == n)
                {
                    List<int[]> res = new List<int[]>();
                    foreach (string s in arr)
                    {
                        int pos = Int32.Parse(s);
                        res.Add(new int[]{ pos / col, pos % col});
                    }
                    return res;
                }

                HashSet<string> curState = new HashSet<string>(arr);
                int x = cur.Item1 / col, y = cur.Item1 % col;
                string state = cur.Item2;
                if (machineSet.Contains(cur.Item1) && !curState.Contains(cur.Item1.ToString()))
                {
                    if (state.Length == 0)
                        state = cur.Item1.ToString();
                    else
                       state += "," + cur.Item1;
                }
                if (y == 0)
                {
                    //move right
                    Tuple<int, string,int> tright = new Tuple<int, string,int>(cur.Item1 + 1, state,1);
                    if (!visited.Contains(tright))
                        queue.Enqueue(tright);

                    if ((x + 1) * col + y >= row * col)
                        continue;

                    //move down
                    Tuple<int, string,int> tdown = new Tuple<int, string,int>((x + 1) * col + y, state,1);
                    if (!visited.Contains(tdown))
                    {
                        queue.Enqueue(tdown);
                        visited.Add(tdown);   
                    }

                }
                else if (y == col - 1)
                {
                    //move left
                    Tuple<int, string,int> tleft = new Tuple<int, string,int>(cur.Item1 - 1, state,-1);                    

                    if (!visited.Contains(tleft))
                        queue.Enqueue(tleft);


                    if ((x + 1) * col + y >= row * col)
                        continue;

                    //move down
                    Tuple<int, string,int> tdown = new Tuple<int, string,int>((x + 1) * col + y, state,-1);
                    if (!visited.Contains(tdown))
                    {
                        queue.Enqueue(tdown);
                        visited.Add(tdown);
                    }
                }
                else
                {
                    //either left or right
                    Tuple<int, string,int> tmove = new Tuple<int, string,int>(cur.Item1 + cur.Item3, state, cur.Item3);

                    if (!visited.Contains(tmove))
                    {
                        queue.Enqueue(tmove);
                        visited.Add(tmove);
                    }

                    //state change, can change direction
                    if (state != cur.Item2)
                    {
                        Tuple<int, string, int> tmove2 = new Tuple<int, string, int>(cur.Item1 - cur.Item3, state, -cur.Item3);

                        if (!visited.Contains(tmove2))
                        {
                            queue.Enqueue(tmove2);
                            visited.Add(tmove2);
                        }
                    }

                    
                }
            }

            return null;
        }
回复

使用道具 举报

🔗
daisy35 2018-9-24 03:32:13 | 只看该作者
全局:
第三题union find
回复

使用道具 举报

🔗
sweetwater 2018-9-26 02:27:17 | 只看该作者
全局:
论坛匿名用户 发表于 2018-9-23 04:50
修机器的人每次修一列的时候,只能走到最右边再往下,或是原路返回从最左边往下,这个是面试官的要求,在 ...

那如果选择原路返回是指不修吗?后面还得回来修?
回复

使用道具 举报

🔗
nanbei 2018-9-26 03:00:16 | 只看该作者
全局:
为啥只有四道题目啊?
回复

使用道具 举报

🔗
fropen 2018-9-26 03:20:53 | 只看该作者
全局:
sweetwater 发表于 2018-9-26 02:27
那如果选择原路返回是指不修吗?后面还得回来修?

修啊,我觉得题目是这样的:
01000
10001
11000
10101
你走逆时针方向,修最近的1个或2个机器,共需要
第一行:修好后原路返回 2*2
第二行左半部:1*2
3: 2*2
4: 5步 不返回
接着修第2行右半部 1
共需要16步,不考虑返回原点和行间步数。
如果一行一行修 就需要5*4=20步
回复

使用道具 举报

🔗
fropen 2018-9-26 03:33:34 | 只看该作者
全局:
第一题暴力搜索可以。Dijakastra最短路径算法可以吗?!
回复

使用道具 举报

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

本版积分规则

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