最短路
cherish__lin
I want to be better!
展开
-
G - MPI Maelstrom(最短路中的最长路)
题意:有n个点,求从一个点到其他所有点的最短路中的最长路。SPFA和Dijkstra都可以。SPFA:#include<iostream>#include<cstring>#include<vector>#include<queue>#include<stdio.h>const int maxn=108;const ...原创 2019-02-02 16:30:20 · 205 阅读 · 0 评论 -
XYZZY(SPFA判正环)
It has recently been discovered how to run open-source software on the Y-Crate gaming device. A number of enterprising designers have developed Advent-style games for deployment on the Y-Crate. Your j...原创 2019-04-11 11:05:32 · 355 阅读 · 0 评论 -
HDU Today(最短路)
经过锦囊相助,海东集团终于度过了危机,从此,HDU的发展就一直顺风顺水,到了2050年,集团已经相当规模了,据说进入了钱江肉丝经济开发区500强。这时候,XHD夫妇也退居了二线,并在风景秀美的诸暨市浬浦镇陶姚村买了个房子,开始安度晚年了。这样住了一段时间,徐总对当地的交通还是不太了解。有时很郁闷,想去一个地方又不知道应该乘什么公交车,在什么地方转车,在什么地方下车(其实徐总自己有车,却一定要与...原创 2019-04-10 23:32:47 · 101 阅读 · 0 评论 -
7-5 拯救007(升级版) (30 分)(路径输出)
在老电影“007之生死关头”(Live and Let Die)中有一个情节,007被毒贩抓到一个鳄鱼池中心的小岛上,他用了一种极为大胆的方法逃脱 —— 直接踩着池子里一系列鳄鱼的大脑袋跳上岸去!(据说当年替身演员被最后一条鳄鱼咬住了脚,幸好穿的是特别加厚的靴子才逃过一劫。)设鳄鱼池是长宽为100米的方形,中心坐标为 (0, 0),且东北角坐标为 (50, 50)。池心岛是以 (0, 0) 为...原创 2019-03-25 09:35:31 · 2004 阅读 · 7 评论 -
L2-001 紧急救援 (25 分)(Dijkstra原始模板)
作为一个城市的应急救援队伍的负责人,你有一张特殊的全国地图。在地图上显示有多个分散的城市和一些连接城市的快速道路。每个城市的救援队数量和每一条连接两个城市的快速道路长度都标在地图上。当其他城市有紧急求助电话给你的时候,你的任务是带领你的救援队尽快赶往事发地,同时,一路上召集尽可能多的救援队。输入格式:输入第一行给出4个正整数N、M、S、D,其中N(2≤N≤500)是城市的个数,顺便假设城市...原创 2019-03-24 23:57:57 · 391 阅读 · 1 评论 -
7-1 垃圾箱分布 (30 分)
大家倒垃圾的时候,都希望垃圾箱距离自己比较近,但是谁都不愿意守着垃圾箱住。所以垃圾箱的位置必须选在到所有居民点的最短距离最长的地方,同时还要保证每个居民点都在距离它一个不太远的范围内。现给定一个居民区的地图,以及若干垃圾箱的候选地点,请你推荐最合适的地点。如果解不唯一,则输出到所有居民点的平均距离最短的那个解。如果这样的解还是不唯一,则输出编号最小的地点。输入格式:输入第一行给出4个正...原创 2019-03-24 23:15:35 · 1871 阅读 · 1 评论 -
最短路小结
通过对最短路的学习,我已经部分掌握了3大算法及其变形,会用一些知识去解决问题,但学无止境,仍有许多知识我知之甚少,我希望通过我的努力会变得越来越强。Floyd经典算法适合多源最短路,由于复杂度较高,适合数据较小的题目,但也有些题目可由Floyd的变形去做。Dijkstra算法为单源最短路,主要思想就是将所有的顶点分成2部分,已知最短路程的集合P和未知最短路程的集合Q,用vis数组标记该点是否在...原创 2019-02-10 22:02:59 · 156 阅读 · 0 评论 -
F - Wormholes (负环)
While 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 its destination at a time that i...原创 2019-02-10 21:43:16 · 172 阅读 · 0 评论 -
M - 昂贵的聘礼
年轻的探险家来到了一个印第安部落里。在那里他和酋长的女儿相爱了,于是便向酋长去求亲。酋长要他用10000个金币作为聘礼才答应把女儿嫁给他。探险家拿不出这么多金币,便请求酋长降低要求。酋长说:"嗯,如果你能够替我弄到大祭司的皮袄,我可以只要8000金币。如果你能够弄来他的水晶球,那么只要5000金币就行了。"探险家就跑到大祭司那里,向他要求皮袄或水晶球,大祭司要他用金币来换,或者替他弄来其他的东西,...原创 2019-02-09 23:36:28 · 75 阅读 · 0 评论 -
W - Test for Job (记忆化搜索)
Mr.Dog was fired by his company. In order to support his family, he must find a new job as soon as possible. Nowadays, It's hard to have a job, since there are swelling numbers of the unemployed. S...原创 2019-02-09 22:01:56 · 186 阅读 · 0 评论 -
T - Sightseeing trip
There is a travel agency in Adelton town on Zanzibar island. It has decided to offer its clients, besides many other attractions, sightseeing the town. To earn as much as possible from this attraction...原创 2019-02-09 21:00:41 · 502 阅读 · 0 评论 -
P - The Shortest Path in Nya Graph
This 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 algoritmo. If you do not understand a word of this paragraph, just ...原创 2019-02-06 22:51:13 · 197 阅读 · 0 评论 -
V - Pandaland (最小环,堆优化的Dijkstra)
Mr. Panda lives in Pandaland. There are many cities in Pandaland. Each city can be treated as a point on a 2D plane. Different cities are located in different locations. There are also M bidirectiona...原创 2019-02-06 20:21:58 · 507 阅读 · 0 评论 -
O - Extended Traffic(SPFA+负环+前向星)
#include<iostream>#include<cstring>#include<stdio.h>#include<queue>using namespace std;const int maxn = 100010;const int INF = 0x3f3f3f3f;int dis[maxn],head[maxn],vis[m...原创 2019-02-03 18:20:24 · 137 阅读 · 0 评论 -
K - Candies (差分约束+最短路)
有n个孩子,m个关系;关系分别有3个数u,v,w。代表v的糖果数不能多于u w个,也就是dis[v]<=dis[u]+w;这就转换成if(dis[v]>dis[u]+w) dis[v]=dis[u]+w.1:SPFA+stack#include<iostream>#include<queue>#include<...原创 2019-02-02 18:57:09 · 184 阅读 · 0 评论 -
I - Arbitrage (正环)
题目就是判是否存在正环:重点是货币是字符类型的,怎么将他映射为数字。这里可以用c++中STL中的map,也可以用字符串寻找。1:SPFA:#include<iostream>#include<cstring>#include<queue>#include<stdio.h>using namespace std;struct Q{...原创 2019-02-02 18:08:40 · 243 阅读 · 0 评论 -
K - Highway Project
Edward, the emperor of the Marjar Empire, wants to build some bidirectional highways so that he can reach other cities from the capital as fast as possible. Thus, he proposed the highway project.The...原创 2019-04-10 00:18:26 · 267 阅读 · 0 评论