poj 2387 Til the Cows Come Home
来源:互联网 发布:桌面数字时钟软件 编辑:程序博客网 时间:2024/06/18 14:52
这是一个最短路径问题,求Bessie最少的开销。需要注意的是,本题是个无向图,并非有向图,存储时得注意到这个问题。
用Bellman-Ford算法即可解决问题。
#include <iostream>
using namespace std;
struct point {
int begin;
int end;
int length;
}s[5000];
int n, t;
int an[5000];
int main()
{
while (cin >> t >> n)//数据输入有多组
{
int i = 1;
while (i <= t)
{
cin >> s[i].begin >> s[i].end >> s[i].length;
s[i + t].begin = s[i].end;//需要考虑到重边的因素
s[i + t].end = s[i].begin;
s[i + t].length = s[i].length;
i++;
}
for (i = 1; i <= n; i++)
an[i] = 999999999;
an[1] = 0;
for (int k = 1; k <= n - 1; k++)
{
for (int sb = 1; sb <= 2*t; sb++)
{
if (an[s[sb].end] > an[s[sb].begin] + s[sb].length)
an[s[sb].end] = an[s[sb].begin] + s[sb].length;
}
}
cout << an[n] << endl;
}
//system("pause");
return 0;
}
- POJ 2387 Til the Cows Come Home
- poj 2387 Til the Cows Come Home
- poj 2387 Til the Cows Come Home
- poj 2387 Til the Cows Come Home
- POJ 2387 Til the Cows Come Home
- POJ 2387 Til the Cows Come Home
- POJ 2387 Til the Cows Come Home
- Poj 2387 Til the Cows Come Home
- poj 2387 Til the Cows Come Home
- POJ 2387 Til the Cows Come Home
- poj 2387 Til the Cows Come Home
- POJ-2387-Til the Cows Come Home
- poj 2387 Til the Cows Come Home
- poj 2387 Til the Cows Come Home
- POJ 2387 Til the Cows Come Home
- POJ 2387 Til the Cows Come Home
- POJ 2387 Til the Cows Come Home
- POJ 2387 Til the Cows Come Home
- 轻松入门React和Webpack
- ndk jstring 与cha*相互转换
- 应用中Matlab语句学习笔记总结1
- disruptor --神奇的缓存行填充1
- 欢迎使用CSDN-markdown编辑器
- poj 2387 Til the Cows Come Home
- 访问权限,public private , default ,protected
- 区间覆盖问题
- SPFA算法(求最短路径)
- apache服务的基本概念(DSO、MPM)
- 第五周项目2游戏中的角色类
- 使用ViewFlipper实现图片自动切换,并支持手势滑动切换
- Python图像处理之边缘检测
- 1010.一元多项式求导 (25)