2014-05-08 23:45
原题:
How would you use Dijkstra's algorithm to solve travel salesman problem, which is to find a shortest path from a starting node back to the starting node and visits all other node exactly once.
题目:如何用Dijkstra算法来解决TSP问题?(谁会出这种题,这又是“Guy”从哪儿copy来的?)
解法:对于这种问题我不知道该说什么。一个多项式级别的算法来解决NP问题,这已经超出了面试题或者教科书的范畴吧?这个“Guy”自己写的代码都够呛,还能问别人这种问题,实在让人无力吐槽。Dijkstra算法用于解决单源最短路径问题,而且要求没有负权的边。就算是用其他算法来近似最优解,也应该用类似最小生成树的算法吧。所以我觉得这个“Guy”应该被永久禁止发帖,完全是在误导我们这些辛辛苦苦做面试题的人。找个工作容易吗?
代码:
1 // http://www.careercup.com/question?id=5085331422445568 2 // Answer: 3 // Dijkstra Algorithm is not for TSP, why would you expect to solve NP-hard problems with O(n ^ 2) efforts? 4 // Comment: 5 // 1. Difficult question. 6 // 2. Vague description. 7 // 3. Strange indication. 8 // 4. Stupid discussion. 9 // Based on the judgement above, I believe that 'guy' is a complete amateur. Excellent programmers don't ask stupid questions, but he did. 10 // The reason I'm complaining is that, he pretended to have google interview experience and posted a lot of fake questions only to trick us. 11 // He doesn't even know how to calculate the distance between two points? 12 // He doesn't know what volatile means. 13 // He keeps asking stupid questions. 14 // SO HOW THE HELL DOES THIS 'GUY' HAVE SO MANY GOOGLE INTERVIEWS? 15 // He's site reliability engineer at Boeing, really? 16 // I hate liars, especially foolish liars! 17 // Down vote for every question he posted. 18 int main() 19 { 20 return 0; 21 }
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· .NET10 - 预览版1新功能体验(一)