POJ2387 Til the Cows Come Home
来源:互联网 发布:微信怎么发淘宝联盟 编辑:程序博客网 时间:2024/06/06 03:19
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 the morning milking. Bessie needs her beauty sleep, so she wants to get back as quickly as possible.
(只粘了部分题目)
从头复习吧,一个知识点一个知识点地弄。
很久没做忘记怎么写最短路了。
此题唯一的细节就是两个点之间可能有多条路,在计算时选取最短的路,在输入的时候直接比较。
#include<iostream>#include<stdio.h>#include<cstring>#include<algorithm>#include<map>#include<vector>#include<cmath>using namespace std;#define N 1000+5#define MAXN 1000000#define mem(arr,a) memset(arr,a,sizeof(arr))#define INF 0x3f3f3f3f#define LL long long int #define pow(a) (a)*(a)int d[N];int cost[N][N];int vis[N];int t, n;void dijkstra(){ mem(vis, 0); mem(d, INF); d[1] = 0; while (1){ int v = -1; for (int i = 1; i <= n; i++){ if (!vis[i] && (v == -1 || d[i] < d[v] ))v = i; } if (v == -1)break; vis[v] = 1; for (int i = 1; i <= n; i++){ if (d[i]>d[v] + cost[v][i]) d[i] = d[v] + cost[v][i]; } } cout << d[n] << endl;}int main(){ cin >> t >> n; mem(cost, INF); while (t--){ int a, b; cin >> a >> b; int c; cin >> c; cost[a][b]=cost[b][a]=min(cost[a][b], c); } dijkstra();}
阅读全文
0 0
- poj2387- Til the Cows Come Home
- poj2387- Til the Cows Come Home
- POJ2387 Til the Cows Come Home
- POJ2387 Til the Cows Come Home【Dijkstra】
- POJ2387----Til the Cows Come Home(dijkstra)
- POJ2387---Til the Cows Come Home
- POJ2387 Til the Cows Come Home
- [poj2387] Til the Cows Come Home
- poj2387 Til the Cows Come Home
- poj2387 Til the Cows Come Home
- poj2387 Til the Cows Come Home
- POJ2387 Til the Cows Come Home
- POJ2387 Til the Cows Come Home
- Poj2387- Til the Cows Come Home
- POJ2387 Til the Cows Come Home
- POJ2387 Til the Cows Come Home
- POJ2387-Til the Cows Come Home
- POJ2387 Til the Cows Come Home
- IDEA Spinrg boot 热部署配置
- 基于socket的TCP和UDP通讯的简单建立
- springioc容器学习第三篇----ApplicationContext容器初始化
- h5面试 &&和||的坑,你踩过吗?
- javascript中事件循环机制
- POJ2387 Til the Cows Come Home
- hadoop 配置文件详解
- java NIO之MappedByteBuffer
- Python实现简单的电话簿功能
- python练习(十一)
- django中urls和views的基本用法
- 8.12 无限序列 1861
- 阿牛的EOF牛肉串
- 02 权限(用户组以及文件的权限)(特殊权限位)