洛谷 P1339 [USACO09OCT]热浪Heat Wave(最短路)
嗯...
题目链接:https://www.luogu.org/problem/P1339
这道题是水的不能在水的裸最短路问题...这里用的dijkstra
但是自己进了一个坑——
因为有些城市之间可能还没有道路,自己只是将其初始化为0,而应该初始化为0x3f3f,从而表示两个城市之间没有道路...
AC代码:
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring> using namespace std;
const int inf = 0x3f3f;
int n, c, ts, te, dis[], vis[], g[][]; inline void dijkstra(int x){
for(int i = ; i <= n; i++) dis[i] = (i == x ? : inf);
for(int i = ; i <= n; i++){
int t = , y = inf;
for(int j = ; j <= n; j++) if(!vis[j] && dis[j] <= y) y = dis[t = j];
vis[t] = ;
for(int j = ; j <= n; j++) dis[j] = min(dis[j], dis[t] + g[t][j]);
}
} int main(){
memset(g, 0x3f3f, sizeof(g));//初始化!!
scanf("%d%d%d%d", &n, &c, &ts, &te);
for(int i = ; i <= c; i++){
int u, v, w;
scanf("%d%d%d", &u, &v, &w);
g[u][v] = g[v][u] = w;
}
dijkstra(ts);
printf("%d", dis[te]);
return ;
}
AC代码
洛谷 P1339 [USACO09OCT]热浪Heat Wave(最短路)的更多相关文章
- 洛谷P1339 [USACO09OCT]热浪Heat Wave(最短路)
题目描述 The good folks in Texas are having a heatwave this summer. Their Texas Longhorn cows make for g ...
- 洛谷—— P1339 [USACO09OCT]热浪Heat Wave
P1339 [USACO09OCT]热浪Heat Wave 题目描述 The good folks in Texas are having a heatwave this summer. Their ...
- 洛谷 P1339 [USACO09OCT]热浪Heat Wave (堆优化dijkstra)
题目描述 The good folks in Texas are having a heatwave this summer. Their Texas Longhorn cows make for g ...
- 洛谷 P1339 [USACO09OCT]热浪Heat Wave
题目链接:https://www.luogu.org/problemnew/show/P1339 解题思路: 一道简单的最短路水题,dijkstra解法模板思路:https://www.cnblogs ...
- 洛谷 P1339 [USACO09OCT]热浪Heat Wave(dijkstra)
题目链接 https://www.luogu.org/problemnew/show/P1339 最短路 解题思路 dijkstra直接过 注意: 双向边 memset ma数组要在读入之前 AC代码 ...
- 洛谷P1339 [USACO09OCT]热浪Heat Wave 题解
题目传送门 这道题实际非常简单好奇是怎么变黄的... 其实也就是一个SPFA,本人非常懒,不想打邻接表,直接用矩阵就好啦... #include<bits/stdc++.h> using ...
- 洛谷P1339 [USACO09OCT]热浪Heat Wave
思路:裸SPFA过一遍(建议使用邻接链表存储),无向图,无向图,无向图,重要的事情要说三遍!!!蜜汁RE是什么鬼????第九个点数组开到20K,第十个点数组开到30K才AC.或许我代码写的有bug?( ...
- 洛谷 1339 [USACO09OCT]热浪Heat Wave
[题解] 最短路.那么直接写dijkstra就好了. #include<cstdio> #include<algorithm> #include<cstring> ...
- [最短路]P1339 [USACO09OCT]热浪Heat Wave
题目描述 The good folks in Texas are having a heatwave this summer. Their Texas Longhorn cows make for g ...
随机推荐
- 浅谈DAO工厂设计模式(工厂模式的好处)
随着软件分层设计的流行及广泛的应用,对于DAO的设计模式大家已经不再陌生了,DAO层已经在软件系统的开发中成为必不可少的一层,将后台的数据层和前台的VO进行分离.前段时间也针对于DAO的设计介绍过一个 ...
- 【转载】C/C++编译过程分析
转自:http://www.360doc.com/content/14/0109/16/835125_343879650.shtml C/C++编译过程 C/C++编译过程主要分为4个过程 1) 编译 ...
- Redis如果内存满了怎么办?
Redis占用内存大小 我们知道Redis是基于内存的key-value数据库,因为系统的内存大小有限,所以我们在使用Redis的时候可以配置Redis能使用的最大的内存大小. 1.通过配置文件配置 ...
- arcgis中的load data加载数据
该工具通过设定字段的对应关系将一个要素类(feature class)的数据加载到另一个要素类里面.通过选择应加载到每个目标字段中的源字段,将匹配源字段中的数据加载到目标数据中. 还可以设置查询,仅加 ...
- map-apply-applymap
In [1]: import warnings import math import pandas as pd import numpy as np import matplotlib warning ...
- PHP高并发和大流量怎么解决?
PHP高并发和大流量的解决方案 一 高并发的概念 在互联网时代,并发,高并发通常是指并发访问.也就是在某个时间点,有多少个访问同时到来. 二 高并发架构相关概念 1.QPS (每秒查询率) : 每秒钟 ...
- 如何将mongo查询结果导出到文件中
1.新建一个js文件,将查询方法写进去,如dump.js,文件内容如下 var c = db.campaign.find({status:1}).limit(5) while(c.hasNext()) ...
- Linux - 命令 - 查找命令总结
关于查找文件的几个命令 一.find命令 find是最常用也是最强大的查找命令,可以查找任何类型的文件 find命令的一般格式: find <指定目录><指定条件><指定 ...
- 概率dp poj2096
/** dp求期望的题. 题意:一个软件有s个子系统,会产生n种bug. 某人一天发现一个bug,这个bug属于某种bug,发生在某个子系统中. 求找到所有的n种bug,且每个子系统都找到bug,这样 ...
- Python学习(七)——匿名函数、map函数、filter函数、reduce函数与其他内置函数
匿名函数 lambda x: x + 1 # lambda:定义匿名函数的关键字 # x:形参 # x+1:程序处理逻辑 fun = lambda x: x + 1 print(fun(5)) #6 ...