hdu 2680 Choose the best route 解题报告
题目链接: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;
- #define INF 0xfffffff
- const int maxn = + ;
- int dist[maxn], map[maxn][maxn], vis[maxn];
- int n, m, s;
- void Init()
- {
- for (int i = ; i <= n; i++)
- {
- for (int j = ; j <= n; j++)
- map[i][j] = (i == j ? : INF);
- }
- int p, q, t, w;
- for (int i = ; i < m; i++)
- {
- scanf("%d%d%d", &p, &q, &t);
- if (map[p][q] > t)
- map[p][q] = t; // 写成map[p][q] = map[q][p] = t 会wa的!!!
- }
- scanf("%d", &w);
- for (int i = ; i < w; i++)
- {
- scanf("%d", &p);
- map[][p] = map[p][] = ;
- }
- for (int i = ; i <= n; i++)
- dist[i] = map[][i];
- }
- void Dijkstra()
- {
- int u, maxx;
- memset(vis, , sizeof(vis));
- for (int i = ; i <= n; i++)
- {
- maxx = INF;
- for (int j = ; j <= n; j++)
- {
- if (!vis[j] && dist[j] < maxx)
- maxx = dist[u=j];
- }
- vis[u] = ;
- for (int j = ; j <= n; j++)
- {
- if (dist[j] > dist[u] + map[u][j])
- dist[j] = dist[u] + map[u][j];
- }
- }
- }
- int main()
- {
- while (scanf("%d%d%d", &n, &m, &s) != EOF)
- {
- Init();
- Dijkstra();
- printf("%d\n", dist[s] == INF ? - : dist[s]);
- }
- return ;
- }
hdu 2680 Choose the best route 解题报告的更多相关文章
- hdu 2680 Choose the best route
题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=2680 Choose the best route Description One day , Kiki ...
- hdu 2680 Choose the best route (dijkstra算法 最短路问题)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2680 Choose the best route Time Limit: 2000/1000 MS ( ...
- HDU 2680 Choose the best route 最短路问题
题目描述:Kiki想去他的一个朋友家,他的朋友家包括所有的公交站点一共有n 个,一共有m条线路,线路都是单向的,然后Kiki可以在他附近的几个公交站乘车,求最短的路径长度是多少. 解题报告:这道题的特 ...
- hdu 2680 Choose the best route (dijkstra算法)
题目:http://acm.hdu.edu.cn/showproblem.php?pid=2680 /************************************************* ...
- HDU 2680 Choose the best route(SPFA)
Problem DescriptionOne day , Kiki wants to visit one of her friends. As she is liable to carsickness ...
- HDU 2680 Choose the best route(多起点单终点最短路问题)题解
题意:小A要乘车到s车站,他有w个起始车站可选,问最短时间. 思路:用Floyd超时,Dijkstra遍历,但是也超时.仔细看看你会发现这道题目好像是多源点单终点问题,终点已经确定,那么我们可以直接转 ...
- HDU 2068 Choose the best route
http://acm.hdu.edu.cn/showproblem.php?pid=2680 Problem Description One day , Kiki wants to visit one ...
- hdu 1002.A + B Problem II 解题报告
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1002 题目意思:就是大整数加法. 两年几前做的,纯粹是整理下来的. #include <stdi ...
- hdoj 2680 choose the best route
Problem Description One day , Kiki wants to visit one of her friends. As she is liable to carsicknes ...
随机推荐
- MongoDB_语法命令
可以通过MongoDB shell 来连接MongoDB服务: ./mongo 进入交互 数据库-->集合-->文档 几个文档就组成了集合,可以设置固定大小的集合,集合就会有过期机制, ...
- R语言入门---杂记(一)---R的常用函数
1.nchar():查看字符串长度. 2.rev(): 给你的数据翻个个 3.sort():给你数据排个序(默认从小到大依次排列) 4.runif():产生均匀分布的随机数 #runif
- Working with multiple environments
ASP.NET Core引入了对多个环境(例如开发,暂存和生产环境)的支持. 可以用环境变量来指示应用程序正在运行的环境,从而让app来做相应的配置. Development, Staging, Pr ...
- 小程序-列表块/类式ul-li格式(1)
摘要 目前列表能布局出来,但是目前我个人还没解决的问题是:如果每个列表块都有详情页怎么解决呢? 1:我的效果图 2.正常的每个都能点击的html 注:上面的代码确实能够实现我的每个[menu2_vie ...
- cart树剪枝
当前子树的损失函数: $C_a(T) = C(T) + a|T|$, 其中$C(T)$为对训练数据的预测误差,$|T|$为树的叶子结点数目,反映模型的复杂度.对固定的$a$,一定存在使损失函数$C_a ...
- 转: memcached Java客户端spymemcached的一致性Hash算法
转自:http://colobu.com/2015/04/13/consistent-hash-algorithm-in-java-memcached-client/ memcached Java客户 ...
- CellularAutomation(细胞自己主动机)
CellularAutomation(细胞自己主动机) 细胞自己主动机(英语:Cellular automaton).又称格状自己主动机.元胞自己主动机,是一种离散模型,在可算性理论.数学及理论生物学 ...
- UVA 11246 - K-Multiple Free set(数论推理)
UVA 11246 - K-Multiple Free set 题目链接 题意:一个{1..n}的集合.求一个子集合.使得元素个数最多,而且不存在有两个元素x1 * k = x2,求出最多的元素个数是 ...
- BFS和DFS记录路径
DFS记录路径的意义好像不大,因为不一定是最短的,但是实现起来却很简单. #include<math.h> #include<stdio.h> #include<queu ...
- 【dotnet跨平台】"dotnet restore"和"dotnet run"都做了些什么?
[dotnet跨平台]"dotnet restore"和"dotnet run"都做了些什么? 前言: 关于dotnet跨平台的相关内容.能够參考:跨平台.NE ...