2012年7月2日

【转载】SPFA算法

摘要: 【转载】SPFA算法算法简介 SPFA(Shortest Path Faster Algorithm)是Bellman-Ford算法的一种队列实现,减少了不必要的冗余计算。也有人说SPFA本来就是Bellman-Ford算法,现在广为流传的Bellman-Ford算法实际上是山寨版。求单源最短路的SPFA算法的全称是:Shortest Path Faster Algorithm。 从名字我们就可以看出,这种算法在效率上一定有过人之处。 很多时候,给定的图存在负权边,这时类似Dijkstra等算法便没有了用武之地,而Bellman-Ford算法的复杂度又过高,SPFA算法便派上用场了。 简洁起见 阅读全文

posted @ 2012-07-02 14:45 yumao 阅读(141) 评论(0) 推荐(0) 编辑

优先队列实例 poj 3253

摘要: 该题运用哈夫曼树,用优先队列求出两个最小的节点值,相加好push进队列中。知道队列为空为止。DescriptionFarmer John wants to repair a small length of the fence around the pasture. He measures the fence and finds that he needs N (1 ≤ N ≤ 20,000) planks of wood, each having some integer length Li (1 ≤ Li ≤ 50,000) units. He then purchases a single 阅读全文

posted @ 2012-07-02 00:01 yumao 阅读(127) 评论(0) 推荐(0) 编辑

导航