图论
five_east_west
这个作者很懒,什么都没留下…
展开
-
poj 1182 食物链——并查集
食物链Description动物王国中有三类动物A,B,C,这三类动物的食物链构成了有趣的环形。A吃B, B吃C,C吃A。现有N个动物,以1-N编号。每个动物都是A,B,C中的一种,但是我们并不知道它到底是哪一种。有人用两种说法对这N个动物所构成的食物链关系进行描述:第一种说法是"1 X Y",表示X和Y是同类。第二种说法是"2 X Y",表示X吃Y。此人对N个动物,用上述两种说法,一句接一句地说出K句话,这K句话有的是真的,有的是假的。当一句话满足下列三条之一时,这句话就是假话,否则就是真话原创 2020-10-11 20:29:47 · 73 阅读 · 0 评论 -
poj 3255 Roadblocks——dijkstra次短路径
RoadblocksDescriptionBessie has moved to a small farm and sometimes enjoys returning to visit one of her best friends. She does not want to get to her old home too quickly, because she likes the scenery along the way. She has decided to take the second-s原创 2020-10-11 11:40:21 · 253 阅读 · 0 评论 -
Frogger——dijkstra算法
Freddy Frog is sitting on a stone in the middle of a lake. Suddenly he notices Fiona Frog who is sitting on another stone. He plans to visit her, but since the water is dirty and full of tourists’ sunscreen, he wants to avoid swimming and instead reach her原创 2020-08-12 00:03:31 · 169 阅读 · 0 评论 -
昂贵的聘礼——dijkstra+枚举区间
一、题目年轻的探险家来到了一个印第安部落里。在那里他和酋长的女儿相爱了,于是便向酋长去求亲。酋长要他用10000个金币作为聘礼才答应把女儿嫁给他。探险家拿不出这么多金币,便请求酋长降低要求。酋长说:"嗯,如果你能够替我弄到大祭司的皮袄,我可以只要8000金币。如果你能够弄来他的水晶球,那么只要5000金币就行了。“探险家就跑到大祭司那里,向他要求皮袄或水晶球,大祭司要他用金币来换,或者替他弄来其他的东西,他可以降低价格。探险家于是又跑到其他地方,其他人也提出了类似的要求,或者直接用金币换,或者找到其他东西原创 2020-08-09 18:01:15 · 259 阅读 · 0 评论 -
Bellman-Ford算法
如果给定一个图是一个DAG,就可以按拓扑排序给顶点编号,并利用这条递推关系式计算出d。但是,如果图中有圈,就无法依赖这样的顺序进行计算。在这种情况下,记当前顶点i的最短路长度为d[i],并 设初值d[s]=0,d[i[=INF(足够大的常数)d[s]=0, d[i[=INF(足够大的常数)d[s]=0,d[i[=INF(足够大的常数),再不断使用这条递推关系式更新d的值,就可以计算出新的d。只要图中不存在负圈,这样的更新操作就是有限的。结束之后的d就是所求的最短距离了。// 从顶点from指向顶点to原创 2020-10-14 10:11:39 · 102 阅读 · 0 评论 -
poj 3169 Layout——bellman-ford
LayoutDescriptionLike everyone else, cows like to stand close to their friends when queuing for feed. FJ has N (2 <= N <= 1,000) cows numbered 1…N standing along a straight line waiting for feed. The cows are standing in the same order as they are原创 2020-10-14 09:44:57 · 147 阅读 · 0 评论