由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
JobHunting版 - 请问一道google面试题
相关主题
请教一道面试题,判断迷宫有没有解G家面试题请教
[算法] word ladder problem问个面试题
问一个word ladder的题目问一个G的面试题
G题求解迷津面试题
问个google面试题一道热门的 Google 面试题
热腾腾g电面 已挂DP interview question
G家一道面试题求问G家onsite丢人了
问个google的面试题。请教问题:gps和google maps背后的算法
相关话题的讨论汇总
话题: element话题: availbe话题: shortest话题: distance话题: matrix
进入JobHunting版参与讨论
1 (共1页)
s******e
发帖数: 108
1
Given a matrix, each element is either s(start), a(availbe), b(block).
There are many s in the matrix,
compute the shortest path of each a(availbe) element.
distance from s or a to ajacent element is 1。
from s or a to b(block) is +ulimited.
compute the shortest distance from a(available) element to all s (start)
node
for exmaple.
s a a a s
the result would be
0 1 2 1 0
for
s b s b s
a b a b a
a b a b a
a a a a a
the result would be
0 + 0 + 0
1 + 1 + 1
2 + 2 + 2
3 4 3 4 3
B*******1
发帖数: 2454
2
我的第一想法是
方法1:
根据矩阵建立一个adj matrix,
然后对每一个s,跑dijkstra,算到每一个a的最短距离,
对于每一个a,如果新的s算出来的最短距离更加小,就更新它的最短距离。
方法2:
建立adj matrix
跑flyoyd- warshal, 算每2点之间最短距离,
对每一个a,找到所有s的距离中最小的那一个。
b*******y
发帖数: 232
3
一开始所有a的值+infty,s的值为0.
然后对每个s开始广播距离(bfs),然后update a的值(也就是距离)
如果a的值没有update,就没必要继续广播下去了。

【在 s******e 的大作中提到】
: Given a matrix, each element is either s(start), a(availbe), b(block).
: There are many s in the matrix,
: compute the shortest path of each a(availbe) element.
: distance from s or a to ajacent element is 1。
: from s or a to b(block) is +ulimited.
: compute the shortest distance from a(available) element to all s (start)
: node
: for exmaple.
: s a a a s
: the result would be

r*****s
发帖数: 51
4
mark
D*******e
发帖数: 151
5
我也这样想的。对每个S做BFS。对每个A,如果算出来的新的距离比原来的小,就更新。跟Bayesian1
说的跑Dijskra是一样的。
如果把所有S放在一起看作一个S做BFS,可能会快,能证明正确性吗?

【在 b*******y 的大作中提到】
: 一开始所有a的值+infty,s的值为0.
: 然后对每个s开始广播距离(bfs),然后update a的值(也就是距离)
: 如果a的值没有update,就没必要继续广播下去了。

m**q
发帖数: 189
6
把所有s放在一起是个好主意,直观上应该是正确的

新。跟Bayesian1

【在 D*******e 的大作中提到】
: 我也这样想的。对每个S做BFS。对每个A,如果算出来的新的距离比原来的小,就更新。跟Bayesian1
: 说的跑Dijskra是一样的。
: 如果把所有S放在一起看作一个S做BFS,可能会快,能证明正确性吗?

u***q
发帖数: 21
7
Since the distance is 1 everywhere for s, a. Any a will be updated with the
shortest distance the first time it's visited. So start from all s should
work.

【在 m**q 的大作中提到】
: 把所有s放在一起是个好主意,直观上应该是正确的
:
: 新。跟Bayesian1

D*******e
发帖数: 151
8
Agree

the

【在 u***q 的大作中提到】
: Since the distance is 1 everywhere for s, a. Any a will be updated with the
: shortest distance the first time it's visited. So start from all s should
: work.

1 (共1页)
进入JobHunting版参与讨论
相关主题
请教问题:gps和google maps背后的算法问个google面试题
a question on finding longest path between two vertices热腾腾g电面 已挂
请教一个算法G家一道面试题求问
LinkIn面经问个google的面试题。
请教一道面试题,判断迷宫有没有解G家面试题请教
[算法] word ladder problem问个面试题
问一个word ladder的题目问一个G的面试题
G题求解迷津面试题
相关话题的讨论汇总
话题: element话题: availbe话题: shortest话题: distance话题: matrix