📣 独立日限时特惠: VIP通行证立减$68
12
返回列表 发新帖
楼主: pilot
跳转到指定楼层
上一主题 下一主题
收起左侧

uber电面

🔗
悲伤网管 2016-4-13 23:11:06 | 只看该作者
全局:
comicrudy 发表于 2016-4-13 18:33
这个不太对吧,比如1 N 2, 2 S 3, 怎么判断1, 3?

我觉得1,3无法判断
回复

使用道具 举报

🔗
hkc593 2016-4-14 02:07:09 | 只看该作者
全局:
我觉的根据例子2
(2)Input :  4 SE 5, 5 SW 3, 3 N 4
    Expected output: True

这个题可能是假设距离的单位都是1吧,要不然这个2)是没法判断true的。比如是4 在(0,0), 5 在(1,-1),3在(1,1), 那么3 N 4 是true,如果3在(2,2), 3和是4 关系是 3 NE 4?
回复

使用道具 举报

🔗
harryhu0705 2016-4-17 04:38:30 | 只看该作者
全局:
hkc593 发表于 2016-4-14 02:07
我觉的根据例子2
(2)Input :  4 SE 5, 5 SW 3, 3 N 4
    Expected output: True

我觉得这个理解是对的!!应该相对距离,n,e,w,s距离都是1, ne,nw,se,sw的距离应该都是sqrt(2)。
对于1n2,3n2这种情况,我认为1,2,3的坐标应该是(0,0),(0,-1),(0,0)
具体方法,我觉得就是设置第一个出现的点的坐标为0,0,然后其他的点如果在hashmap里面没有出现过,那么就是hashmap其实是最好的做法
回复

使用道具 举报

🔗
liurudahai 2016-12-2 09:17:26 | 只看该作者
全局:
harryhu0705 发表于 2016-4-17 04:38
我觉得这个理解是对的!!应该相对距离,n,e,w,s距离都是1, ne,nw,se,sw的距离应该都是sqrt(2)。
对 ...

这个方法感觉是对的,必须假设东西南北距离是1,不然没法判断,TOPOLOGY SORT什么都没用
回复

使用道具 举报

全局:
                • Construct two graphs, one for x-coordinate--Gx, one for y-coordinate--Gy. 
                • For Gx, If x1 < x2, then we have an edge from x1->x2, if x1 > x2, one edge x1<-x2. If x1 == x2, combine x1 and x2 together. 
                • In the end, we check whether there exists a cycle in Gx or Gy. If this is true, then the answer is impossible. 
                • To detect a back edge, we can keep track of vertices currently in recursion stack of function for DFS traversal. If we reach a vertex that is already in the recursion stack, then there is a cycle in the tree. The edge that connects current vertex to the vertex in the recursion stack is back edge. We have used recStack[] array to keep track of vertices in the recursion stack.
回复

使用道具 举报

全局:
wangxinbo1123 发表于 2017-1-3 09:19
• Construct two graphs, one for x-coordinate--Gx, one for y-coordinate--Gy. 
                • ...

我觉得你的方法很好,但是
If x1 == x2, combine x1 and x2 together.
这个部分,岂不是要union find来实现,不过好想也真实没什么其他办法了
回复

使用道具 举报

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

本版积分规则

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