![](https://img-blog.csdnimg.cn/20190927151043371.png?x-oss-process=image/resize,m_fixed,h_224,w_224)
最短路径
最短路径
浪漫些许潦草
这个作者很懒,什么都没留下…
展开
-
poj Til the Cows Come Home(dijkstra,bellman_ford,spfa)
Til the Cows Come HomeDescriptionBessie is out in the field and wants to get back to the barn to get as much sleep as possible before Farmer John wakes her for the morning milking. Bessie ne原创 2017-01-14 16:17:22 · 463 阅读 · 0 评论 -
CodeForces - 666B World Tour(BFS+枚举)
World Tour题目链接: World Tour题意: 给你一张有向图,叫你给出四个点的序列,使得这四个点依次间的最短路之和最大。分析: n到3000,所以直接枚举四个点肯定超时,因此可以枚举b、c两个点,然后BFS预处理出能到b的最远的3个点,和c能到的最远的3个点。 之所以是3个点是因为,有可能备选点会和已定点重合,例如abc都定好了,然后d的备选是a、b,那就漏情况了,所以要备选3原创 2017-05-05 21:00:19 · 523 阅读 · 0 评论 -
nyoj 1238 最少换乘(spfa)
描述 欧洲某城是一个著名的旅游胜地,每年都有成千上万的人前来观光旅行。Dr. Kong决定利用暑假好好游览一番。。年轻人旅游不怕辛苦,不怕劳累,只要费用低就行。但Dr. Kong年过半百,他希望乘坐BUS从住的宾馆到想去游览的景点,期间尽可量地少换乘车。Dr. Kon买了一张旅游地图。他发现,市政部门为了方便游客,在各个旅游景点及宾馆,饭店等地方都设置了一些公交站并开通了一些单程线路。每条单程线原创 2017-04-25 19:13:26 · 522 阅读 · 0 评论 -
poj 昂贵的聘礼(spfa)(枚举)
昂贵的聘礼Description年轻的探险家来到了一个印第安部落里。在那里他和酋长的女儿相爱了,于是便向酋长去求亲。酋长要他用10000个金币作为聘礼才答应把女儿嫁给他。探险家拿不出这么多金币,便请求酋长降低要求。酋长说:"嗯,如果你能够替我弄到大祭司的皮袄,我可以只要8000金币。如果你能够弄来他的水晶球,那么只要5000金币就行了。"探险家就跑到大祭司那里,向他要求皮袄或水原创 2017-02-22 20:04:03 · 432 阅读 · 0 评论 -
FZU 2261 浪里个浪 (多源最短路)(福州大学第十四届程序设计竞赛)
浪里个浪Problem Description TonyY是一个喜欢到处浪的男人,他的梦想是带着兰兰姐姐浪遍天朝的各个角落,不过在此之前,他需要做好规划。现在他的手上有一份天朝地图,上面有n个城市,m条交通路径,每条交通路径都是单行道。他已经预先规划好了一些点作为旅游的起点和终点,他想选择其中一个起点和一个终点,并找出从起点到终点的一条路线亲身体验浪的过程。但是他时间有限,所以想选择耗时最小的,你原创 2017-07-15 08:49:41 · 1322 阅读 · 0 评论 -
poj 1724 ROADS(dfs)||(优先队列+dijkstra)
ROADSDescriptionN cities named with numbers 1 … N are connected with one-way roads. Each road has two parameters associated with it : the road length and the toll that needs to be paid for the road (ex原创 2017-04-13 21:55:33 · 709 阅读 · 0 评论 -
NBUT 1221 Intermediary(优先队列+dijkstra)(状态压缩)
Intermediary问题描述 It is widely known that any two strangers can get to know each other through at most six other people. Now let’s prove this.In the country Intermediary Conducts Personal Communication原创 2017-04-10 12:37:05 · 683 阅读 · 0 评论 -
poj Layout(差分约束)
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原创 2017-02-23 21:02:44 · 856 阅读 · 0 评论 -
hdu 1595 find the longest of the shortest(spfa)(存储并枚举最短路径的边)
find the longest of the shortestProblem Description Marica is very angry with Mirko because he found a new girlfriend and she seeks revenge.Since she doesn’t live in the same city, she started prepari原创 2017-07-17 13:25:20 · 490 阅读 · 0 评论 -
BZOJ 1003 物流运输(最短路+DP)
物流运输Description 物流公司要把一批货物从码头A运到码头B。由于货物量比较大,需要n天才能运完。货物运输过程中一般要转 停好几个码头。物流公司通常会设计一条固定的运输路线,以便对整个运输过程实施严格的管理和跟踪。由于各种 因素的存在,有的时候某个码头会无法装卸货物。这时候就必须修改运输路线,让货物能够按时到达目的地。但是 修改路线是一件十分麻烦的事情,会带来额外的成本。因此物流公原创 2017-07-17 18:16:42 · 547 阅读 · 0 评论 -
poj 3013 Big Christmas Tree (最短路径树)
Big Christmas TreeDescriptionChristmas is coming to KCM city. Suby the loyal civilian in KCM city is preparing a big neat Christmas tree. The simple structure of the tree is shown in right picture.原创 2017-07-17 18:45:48 · 804 阅读 · 0 评论 -
FZU 2271 X (Floyd)(第七届福建省大学生程序设计竞赛)
XProblem Description X is a fully prosperous country, especially known for its complicated transportation networks. But recently, for the sake of better controlling by the government, the president Fa原创 2017-07-19 09:59:03 · 909 阅读 · 0 评论 -
URAL - 1004 Sightseeing Trip(最小环)
Sightseeing Trip题目链接:Sightseeing Trip题意:给你一个无向有环图,有n个点,m条边(可能有重边),问图中的最小环是多少,打印出最小环思路: 一种方法是:对于每一个(u,v),去掉(u,v)这条边,然后最短路跑一边计算出u到v的最短距离s,s+dis[u][v]就是环的长度,遍历找出最小环即可另一种方法是:在用Floyd()松弛之前,对于当前的每一个k,都可以看成存原创 2017-08-02 09:58:45 · 1127 阅读 · 0 评论 -
hdu 6071 Lazy Running(优先队列+dijkstra)(2017 Multi-University Training Contest - Team 4)
Lazy Running题目链接:Lazy Running官方题解: 我们可以先假设一下,从2出发再回到2,w=min(d1,2,d2,3)w=min({d}_{1,2},{d}_{2,3}) 最好的情况是,回到2刚好走了k距离; 最坏的情况是,回到2才走了k-1-x*2*w距离(x为任意值),这时我们需要再走(x+1)*2*w因此,我们的最大花费就是k-1+2*w,最小花费为k所以我原创 2017-08-04 16:52:48 · 1471 阅读 · 0 评论 -
hdu 6201 transaction transaction transaction(最长路)
transaction transaction transaction题目链接:transaction transaction transaction题意:给你一棵树,每个点都有点权,每条边也有边权,要求选择起点S和终点T,使得val点T−val点S−val边{val}_{点T}-{val}_{点S}-{val}_{边}最大思路:建立源点和汇点,源点到树上所有点的权值为p[i]p[i],树上所有点到原创 2017-09-11 12:20:59 · 370 阅读 · 0 评论 -
hdu 6166 Senior Pan(多源最短路径)(二进制划分集合)
Senior PanProblem Description Senior Pan fails in his discrete math exam again. So he asks Master ZKC to give him graph theory problems everyday. The task is simple : ZKC will give Pan a directed gra原创 2017-10-06 20:43:51 · 485 阅读 · 0 评论 -
HAUT 1262 魔法宝石(spfa)(河南工业大学2017校赛)
魔法宝石题目描述小s想要创造n种魔法宝石。小s可以用ai的魔力值创造一棵第i种魔法宝石,或是使用两个宝石合成另一种宝石(不消耗魔力值)。请你帮小s算出合成某种宝石的所需的最小花费。输入第一行为数据组数T(1≤T≤3)。 对于每组数据,首先一行为n,m(1≤n,m≤10^5)。分别表示魔法宝石种类数和合成魔法的数量。 之后一行n个数表示a1到an。(1≤ai≤10^9)。a_i表示合成第i种宝石所原创 2017-04-24 09:43:13 · 1000 阅读 · 0 评论 -
CSU 1336 Interesting Calculator(spfa)
Interesting CalculatorDescription There is an interesting calculator. It has 3 rows of buttons. Row 1: button 0, 1, 2, 3, …, 9. Pressing each button appends that digit to the end of the display.原创 2017-04-05 20:38:55 · 486 阅读 · 0 评论 -
poj Heavy Transportation(dijkstra,spfa)
Heavy TransportationDescriptionBackground Hugo Heavy is happy. After the breakdown of the Cargolifter project he can now expand business. But he needs a clever man who tells him whether th原创 2017-01-15 17:47:33 · 539 阅读 · 0 评论 -
poj Candies(差分约束,spfa栈)
CandiesDescriptionDuring the kindergarten days, flymouse was the monitor of his class. Occasionally the head-teacher brought the kids of flymouse’s class a large bag of candies and had fly原创 2017-02-16 15:16:52 · 785 阅读 · 0 评论 -
poj Invitation Cards(spfa)
Invitation CardsDescriptionIn the age of television, not many people attend theater performances. Antique Comedians of Malidinesia are aware of this fact. They want to propagate theater and,原创 2017-02-16 15:28:19 · 477 阅读 · 0 评论 -
poj Currency Exchange(Bellman_ford变形)
Currency ExchangeDescriptionSeveral currency exchange points are working in our city. Let us suppose that each point specializes in two particular currencies and performs exchange operations原创 2017-01-17 16:07:28 · 560 阅读 · 0 评论 -
poj Wormholes(Bellman_ford寻找负权环)
WormholesDescriptionWhile exploring his many farms, Farmer John has discovered a number of amazing wormholes. A wormhole is very peculiar because it is a one-way path that delivers you to it原创 2017-01-17 19:23:32 · 775 阅读 · 0 评论 -
poj Frogger(Dijkstra,Floyd,Spfa)
FroggerDescriptionFreddy 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 dir原创 2017-01-16 14:37:20 · 494 阅读 · 0 评论 -
poj Cow Contest(传递闭包)
Cow ContestDescriptionN (1 ≤ N ≤ 100) cows, conveniently numbered 1..N, are participating in a programming contest. As we all know, some cows code better than others. Each cow has a certain原创 2017-01-18 15:10:43 · 492 阅读 · 0 评论 -
poj Subway(dijkstra)
SubwayDescriptionYou have just moved from a quiet Waterloo neighbourhood to a big, noisy city. Instead of getting to ride your bike to school every day, you now get to walk and take the subw原创 2017-02-21 19:44:10 · 778 阅读 · 0 评论 -
【CodeForces】500B - New Year Permutation(Floyd)(贪心)
New Year PermutationUser ainta has a permutation p1, p2, ..., pn. As the New Year is coming, he wants to make his permutation as pretty as possible.Permutation a1, a2, ..., an is prett原创 2017-03-01 20:08:48 · 620 阅读 · 0 评论 -
hdu The Shortest Path in Nya Graph(建图+spfa)
The Shortest Path in Nya GraphProblem DescriptionThis is a very easy problem, your task is just calculate el camino mas corto en un grafico, and just solo hay que cambiar un poco el algori原创 2017-02-26 15:33:59 · 394 阅读 · 0 评论 -
poj Arbitrage(Floyd||spfa)
ArbitrageDescriptionArbitrage is the use of discrepancies in currency exchange rates to transform one unit of a currency into more than one unit of the same currency. For example, suppose th原创 2017-01-22 17:03:22 · 461 阅读 · 0 评论 -
hdu 0 or 1(最短路spfa)(本质,抽象)
0 or 1Problem DescriptionGiven a n*n matrix Cij (1ij (1Besides,Xij meets the following conditions:1.X12+X13+...X1n=12.X1n+X2n+...Xn-1n=13.for each i (1ki (1ij (1For examp原创 2017-02-27 13:47:56 · 722 阅读 · 0 评论 -
hdu 4849 Wow! Such City!(最短路)
Wow! Such City!Problem Description Doge, tired of being a popular image on internet, is considering moving to another city for a new way of life. In his country there are N (2 ≤N≤ 1000) cities labele原创 2017-03-30 23:35:00 · 521 阅读 · 0 评论 -
2017 Wuhan University Programming Contest 现场赛 K.Wifi Relay(最短路变形)
题目链接:Wifi Relay思路:直接从第一个点开始,寻找离它最近的点,并更新两点间的距离,类似于最短路的思想 代码:#include<bits/stdc++.h>using namespace std;#define maxn 10010#define min(a,b) (a<b?a:b)#define max(a,b) (a>b?a:b)typedef long long LL;c原创 2017-04-17 19:50:55 · 520 阅读 · 0 评论 -
CSU 1333 Funny Car Racing(spfa)
Funny Car RacingDescription There is a funny car racing in a city with n junctions and m directed roads. The funny part is: each road is open and closed periodically. Each road is associate with原创 2017-04-05 07:38:25 · 756 阅读 · 0 评论 -
hdu 5521 Meeting(优先队列+dijkstra)(建图思想)
MeetingProblem DescriptionBessie and her friend Elsie decide to have a meeting. However, after Farmer John decorated his fences they were separated into different blocks. John’s farm are divided into原创 2017-10-11 21:05:31 · 338 阅读 · 0 评论