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 ...
随机推荐
- [MFC] CString小用例
在实际项目中需要对数字转成的字符串进行格式处理, 如: 50.500000,需要转化成50.5; 1.00000,需要转化成1, 对于编号而言要求都是4位,不足前面补0. 如1转成0001,222转成 ...
- HDU 5015 233 Matrix(网络赛1009) 矩阵快速幂
先贴四份矩阵快速幂的模板:http://www.cnblogs.com/shangyu/p/3620803.html http://www.cppblog.com/acronix/archive/20 ...
- R语言入门视频笔记--8--数据框
一.数据框 使用data.frame函数生成数据框 x <- c(20122014101:20122014128) y <- rnorm(28,85,18) #生成28个平均数为85,方差 ...
- Redis数据结构之整数集合
整数集合是Redis用于保存整数值的集合抽象数据结构,它可以保存类型为int16_t .int32_t或者int64_t的整数值,并且保证集合中不会出现重复元素. 一.整数集合数据结构定义 参数说明: ...
- [Bzoj5254][Fjwc2018]红绿灯(线段树)
5254: [Fjwc2018]红绿灯 Time Limit: 10 Sec Memory Limit: 256 MBSubmit: 31 Solved: 24[Submit][Status][D ...
- CodeWar---将字符串转换为驼峰命名
Convert string to camel case 将字符串转换为驼峰命名 自己的解法 将不是字母和数字的字符用.取代,再根据点划分数组.将下标不为0的数组首字符大写,剩下全部小写 static ...
- C/C++中static关键字作用总结 && 指针与引用的比较
static作用: 常规答案: 1. 全局变量的隐藏:2. 函数体内记忆功能:3.类所有实例共享,static函数不接受this指针,只能访问static成员变量. 拓展:1.全局变量的隐藏,因为在其 ...
- cocos2d-x 3.0 final 移植 android
准备工作 你仅仅要依照上一篇的 cocos2d-x 3.0 final 环境搭建 完毕就能够了 1.编辑proj.android\jni\Android.mk,更改内容例如以下 LOCAL_PATH ...
- IntelliJ IDEA 默认需要进行maven的设置
IntelliJ IDEA 默认需要进行maven的设置 需要指定maven的地址,指定settings.xml的地址: 可以默认的在user/.m2/下面放一个settings.xml文件: 学习: ...
- TFTP服务器
为什么要学习有关TFTP服务器的安装及配置呢?主要是为了后续学习有关linux系统的无人值守安装做准备. TFTP简单文件传输协议,使用UDP的69端口.主要提供文件的上传和下载,TFTP一般是适用于 ...