HDOJ 2680 Dijkstra】的更多相关文章

题目大意: 给你一个有向图,一个起点集合,一个终点,求最短路.... 解题思路: 1.自己多加一个超级源点,把起点集合连接到超级源点上,然后将起点与超级源点的集合的路径长度设为0,这样就称为一个n+1个点的单源最短路算法. #include <stdio.h> #include <string.h> ][]; int n; int Dijkstra(int s,int e){ ]; ]; memset(done,,sizeof(done)); ;i <= n;i++) d[i…
在做PAT的甲1003,思考DFS和图什么的,时间紧张直接去看柳神(日后上传柳神的C++版本)的订阅,得知是dijkstra,转去用hdoj 1874练手,写了两天,终于调出来了 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1874 题目大意:给你点 和 边的数目,接下来输出边的信息(a, b, c表示a和b之间距离为c),最后给你两个数字,表示两点的点信息.让你输出最短路径,没有就-1. 解题思路:dijkstra的思想是贪心,越想越经典. 起…
Problem Description One day , Kiki wants to visit one of her friends. As she is liable to carsickness , she wants to arrive at her friend’s home as soon as possible . Now give you a map of the city’s traffic route, and the stations which are near Kik…
题目:http://acm.hdu.edu.cn/showproblem.php?pid=2680 /************************************************************************/ /* hdu Arbitrage dijkstra算法 题目大意:dijkstra算法,求点与点之间最短距离.因为此题的起始点不定,所以可用 反向图来求得,终点确定,从终点出发,dijkstra算法,求出其他点到终点最小距离. 本题数据量较大,用fl…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2680 Choose the best route Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 7201    Accepted Submission(s): 2350 Problem Description One day , Kiki…
http://acm.hdu.edu.cn/showproblem.php?pid=2680 Problem Description One day , Kiki wants to visit one of her friends. As she is liable to carsickness , she wants to arrive at her friend's home as soon as possible . Now give you a map of the city's tra…
Choose the best route Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 7062    Accepted Submission(s): 2301 Problem Description One day , Kiki wants to visit one of her friends. As she is liable…
畅通工程续 Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 33724    Accepted Submission(s): 12329 Problem Description 某省自从实行了很多年的畅通工程计划后,终于修建了很多路.不过路多了也不好,每次要从一个城镇到另一个城镇时,都有许多种道路方案可以选择,而某些方案要比另一些方案行走…
最短路 Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 38585    Accepted Submission(s): 16862 Problem Description 在每年的校赛里,所有进入决赛的同学都会获得一件很漂亮的t-shirt.但是每当我们的工作人员把上百件的衣服从商店运回到赛场的时候,却是非常累的!所以现在他们想要寻找…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2544 这题的思路可以见这里(同一类型):http://blog.csdn.net/xiaozhuaixifu/article/details/9232921 #include<iostream> using namespace std; const int maxn=101; const int intmax=99999; int weight[maxn][maxn]; //保存权值的邻接矩阵 i…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1874 思路分析:该问题给定一个无向图.起始点和终点,要求求出从起始点到终点的最短距离: 使用Dijkstra算法求出从起始点到所有的其他点的最短路长度即可,如果最短路长度为INT_MAX,表示从起始点到该点没有路径相连: 代码如下: #include <queue> #include <climits> #include <cstdio> #include <vect…
#include <iostream> #include <stdio.h> #include <string.h> #include <cstring> using namespace std; ; ; int map[MAXSIZE][MAXSIZE]; int price[MAXSIZE][MAXSIZE]; int n; void Dijkstra(int s,int e){ bool done[MAXSIZE]; int dis[MAXSIZE],…
题目传送门 题意:起点s到终点t送电,中途会有损耗,问最小损耗是多少 分析:可以转换为单源最短路问题,用优先队列的Dijkstra版本,d[]表示从s出发到当前点的最小损耗,用res保存剩下的电量.当到达t就结束,因为按照w从小到大排序,访问过的点都已经最优,这是贪心思想 收获:复习了Dijkstra,进一步理解Dijkstra的贪心的思想(程序跑得慢,还可优化) 代码: /************************************************ * Author :Ru…
最短路 Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 42716    Accepted Submission(s): 18715 Problem Description 在每年的校赛里,全部进入决赛的同学都会获得一件非常美丽的t-shirt.可是每当我们的工作人员把上百件的衣服从商店运回到赛场的时候,却是非常累的! 所以如今他们想要…
卧槽....最近刷的cf上有最短路,本来想拿这题复习一下.... 题意就是在输出最短路的情况下,经过每个节点会增加税收,另外要字典序输出,注意a到b和b到a的权值不同 然后就是处理字典序的问题,当松弛时发现相同值的时候,判断两条路径的字典序 代码 #include "stdio.h" const int MAXN=110; const int INF=10000000; bool vis[MAXN]; int pre[MAXN]; int cost[MAXN][MAXN],lowcos…
题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=2680 Choose the best route Description One day , Kiki wants to visit one of her friends. As she is liable to carsickness , she wants to arrive at her friend’s home as soon as possible . Now give you a ma…
Dijkstra算法 ———————————最后更新时间:2011.9.25———————————Dijkstra(迪杰斯特拉)算法是典型的最短路径路由算法,用于计算一个节点到其他所有节点的最短路径.主要特点是以起始点为中心向外层层扩展,直到扩展到终点为止.Dijkstra算法能得出最短路径的最优解,但由于它遍历计算的节点很多,所以效率低. Dijkstra算法是很有代表性的最短路算法,在很多专业课程中都作为基本内容有详细的介绍,如数据结构,图论,运筹学等等. 其基本思想是,设置顶点集合S并不断…
HDU Today Time Limit: 15000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 13952    Accepted Submission(s): 3264 Problem Description 经过锦囊相助,海东集团最终度过了危机,从此,HDU的发展就一直顺风顺水,到了2050年,集团已经相当规模了.据说进入了钱江肉丝经济开发区500强.这时候…
Dijkstra(迪杰斯特拉)算法是典型的最短路径路由算法,用于计算一个节点到其他所有节点的最短路径.主要特点是以起始点为中心向外层层扩展,直到扩展到终点为止.Dijkstra算法能得出最短路径的最优解,但由于它遍历计算的节点很多,所以效率低. Dijkstra算法是很有代表性的最短路算法,在很多专业课程中都作为基本内容有详细的介绍,如数据结构,图论,运筹学等等. 其基本思想是,设置顶点集合S并不断地作贪心选择来扩充这个集合.一个顶点属于集合S当且仅当从源到该顶点的最短路径长度已知. 初始时,S…
这道题也是死命TLE.. http://acm.hdu.edu.cn/showproblem.php?pid=2680 /* 使用pair代替结构 */ #include <iostream> #include <cstdio> #include <queue> #include <vector> using namespace std; ; const int INF = 0x3f3f3f3f; typedef pair<int,int> pa…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2680 题目意思:实质就是给定一个多源点到单一终点的最短路. 卑鄙题---有向图.初始化map时 千万不要写成 map[i][j] = map[j][i] = X. #include <iostream> #include <cstdio> #include <cstdlib> #include <cstring> using namespace std; #de…
最短路+01背包 In Action Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 3857    Accepted Submission(s): 1229 Problem Description Since 1945, when the first nuclear bomb was exploded by the Manhattan…
Dijkstra 算法是一种用于计算带权有向图中单源最短路径(SSSP:Single-Source Shortest Path)的算法,由计算机科学家 Edsger Dijkstra 于 1956 年构思并于 1959 年发表.其解决的问题是:给定图 G 和源顶点 v,找到从 v 至图中所有顶点的最短路径. Dijkstra 算法采用贪心算法(Greedy Algorithm)范式进行设计.在最短路径问题中,对于带权有向图 G = (V, E),Dijkstra 算法的初始实现版本未使用最小优先…
FatMouse' Trade Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 56784    Accepted Submission(s): 19009 Problem Description FatMouse prepared M pounds of cat food, ready to trade with the cats g…
Nasty Hacks Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 3049    Accepted Submission(s): 2364 Problem Description You are the CEO of Nasty Hacks Inc., a company that creates small pieces of…
Box of Bricks Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 5994    Accepted Submission(s): 2599 Problem Description Little Bob likes playing with his box of bricks. He puts the bricks one up…
Dijkstra是解决单源最短路径的一般方法,属于一种贪婪算法. 所谓单源最短路径是指在一个赋权有向图中,从某一点出发,到另一点的最短路径. 以python代码为例,实现Dijkstra算法 1.数据结构设计 假设图以单边列表的方式进行输入,本例使用如下的一个图来进行分析: E = ((1,2,2), (1,4,1), (2,4,3), (2,5,10), (3,1,4), (3,6,5), (4,3,2), (4,6,8), (4,7,4), (4,5,2), (5,7,6), (7,6,1)…
最小费用最大流板子,没有压行.利用重标号让边权非负,用Dijkstra进行增广,在理论和实际上都比SPFA增广快得多.教程略去.转载请随意. #include <cstdio> #include <cstring> #include <algorithm> #include <functional> #include <queue> using namespace std; ; const int inf = 0x33333333; typede…
传送门 Frogger Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 39453   Accepted: 12691 Description 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…
传送门 Til the Cows Come Home Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 46727   Accepted: 15899 Description Bessie 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…