Dijkstra
文章平均质量分 78
冷月残星
这个作者很懒,什么都没留下…
展开
-
Dijkstra(机场快线,UVA 11374)
#include using namespace std; const int maxn = 1010; const int inf = 0x3f3f3f3f; struct Edge { int from,to,dist; }; struct HeapNode { int d,u; bool operator < (const HeapNode& rhs) const原创 2017-02-09 21:40:13 · 295 阅读 · 0 评论 -
线段树优化连边,Dijkstra(In Touch,HDU 5361)
第二次被vector卡空间。。。但凡用到了vector,空间复杂度就别想算对了。。。以后少用vector,多用链式前向星。(特别是空间比较紧的时候) 还有一些实现上的失误, a=max(1,i-R[i]); b=max(1,i-L[i]); 改成 a=i-R[i]; b=i-L[i]; 就对了,因为前面的代码会导致不一样的结果。 对于这种问题,我只能说对于那些比原创 2017-07-10 21:37:45 · 481 阅读 · 0 评论 -
邻接表与链式前向星
ZOJ 3877 Earthstone Keeper 又遇到了一道卡空间常数的题目。 如果用链式前向星就刚好卡过,如果用邻接表就超空间。 原因是本题点巨多(1e5),但边相对来讲巨少(每个点最多8条边)。 如果用邻接表来实现的话,一般就用vector嘛,我们都知道vector都是自动扩容的,在空间满了以后,就自动申请多一倍空间。 如下代码所示。 #include #defi原创 2017-04-20 15:35:57 · 3876 阅读 · 0 评论 -
最短路,前缀和优化连边,Dijkstra(UESTC 482,Charitable Exchange)
http://acm.uestc.edu.cn/#/problem/show/482 做了这道题目很有收获,一方面是熟练了优化连边的技巧,另一方面是对Dijkstra有了新的感悟。 关于优化连边的做法: 首先离散化,将1e9范围的数离散化,重新分配编号,这样最多有2e5个节点。 很显然,题目中的边是一种区间到单点的边,所以可以考虑线段树优化连边,可能是因为自己不够熟练,原创 2017-05-01 21:19:37 · 825 阅读 · 0 评论 -
Dijkstra,平面图最大流(动物园大逃亡,LA 3661)
学会了用最短路求平面图的最大流。 http://blog.sina.com.cn/s/blog_60707c0f01011fnn.html 代码 #include #define rep(i,a,b) for(ll i=a;i<=b;i++) using namespace std; typedef long long ll; const ll maxn = 2e6; con原创 2017-02-12 12:41:20 · 461 阅读 · 0 评论 -
Dijkstra(低价空中旅行,LA 3561)
任何最短路的本质都是状态的最短路。其中涉及状态的定义以及状态的转移。 当然你也可以用图论对状态建模,然后再跑普通的Dijkstra。 代码 #include #define rep(i,a,b) for(int i=a;i<=b;i++) using namespace std; const int maxn = 5000; const int inf = 0x3f3f3原创 2017-02-12 10:46:49 · 405 阅读 · 0 评论 -
Dijkstra,最短路(蒸汽式压路机,LA 4128)
任何问题的最短路都是状态的最短路。 代码 #include #include #define rep(i,a,b) for(ll i=a;i<=b;i++) using namespace std; typedef long long ll; const ll maxn = 110; const ll inf = LONG_LONG_MAX>>2; ll dr[4]={-1, 0,原创 2017-02-11 20:15:11 · 383 阅读 · 0 评论 -
Dijkstra,最短路树(战争和物流,LA 4080)
学会了最短路树。 #include #include using namespace std; typedef long long ll; const ll maxn = 110; const ll maxm = 1010; const ll inf = LONG_LONG_MAX>>2; struct Edge { ll from,to,dist; }; struct He原创 2017-02-10 12:48:29 · 821 阅读 · 0 评论 -
Dijkstra,记忆化搜索(林中漫步,UVA 10917)
就是先对终点求一个单源最短路,然后再对起点跑一个记忆化搜索。 一开始搞错家和公司的位置了。。。卒。。。 如果没AC,别太发牢骚,一定是你哪里没做好了。 如果不用心,啥都做不好的。 代码 #include #include using namespace std; typedef long long ll; const ll maxn = 1010; const l原创 2017-02-10 10:33:46 · 388 阅读 · 0 评论 -
贪心,Dijkstra(The path,HDU 5385)
贪心构造距离,Dijkstra构造边。 有一些细节写错了,在遍历边的时候,把e.v写成了i,WA了一段时间。 一开始写代码的时候就要小心。 代码 #include #include #include using namespace std; const int maxn = 100010; const int inf = 0x3f3f3f3f; int n,m; in原创 2017-07-16 12:48:49 · 193 阅读 · 0 评论