FAFU - 1030 最短距离
来源:互联网 发布:阿里云企业邮箱条件 编辑:程序博客网 时间:2024/05/16 14:55
http://acm.fafu.edu.cn/problem.php?id=1030
1.题目:
开车从起始点A到目的地B的路线有多条。给你一张描述待选路线的表(n*n的矩阵A),让你找出行车距离最短的路线。表中表示了任意两个路口的连通情况,以及距离。矩阵元素a(i,j)=0表是路口i,j不连通,a(i,j)!=0表示路口i,j的行车距离。其中起始点A在路口1,目的地B在路口n.
2.代码
#include<iostream>using namespace std;int main(){//ifstream cin("1030.in");int init=1000,j,i,n,k,t,**w,*s,*p,*d;cin >> n;d=new int[n]; s=new int[n];p=new int[n];w=new int*[n];for(i=0;i<n;i++){w[i]=new int[n];} for(i=0;i<n;i++)for(j=0;j<n;j++)cin>>w[i][j];for(s[0]=1,i=1;i<n;i++){s[i]=0;d[i]=w[0][i];if(d[i]<init) p[i]=0;else p[i]=-1;}for(i=1;i<n;i++){t=init;k=1;for(j=1;j<n;j++)if((!s[j])&&(d[j]<t)){t=d[j];k=j;}s[k]=1;for (j=1;j<n;j++)if((!s[j])&&(d[j]>d[k]+w[k][j])) {d[j]=d[k]+w[k][j];p[j]=k;}}cout << d[n-1] << endl;return 0;}
- FAFU - 1030 最短距离
- 最短距离
- 最短距离
- 最短距离
- 最短距离
- FAFU - 1283 最短路
- 两数组最短距离
- 一类最短距离问题
- 两数组最短距离
- 素数最短距离问题
- gis最短距离
- 素数最短距离算法
- 两数组最短距离
- POJ 1450 最短距离
- POJ 2101最短距离
- 两数组最短距离
- 两数组最短距离
- 蓝桥杯练习题 最短距离
- 多机最佳调度
- hdoj 2031 进制转换
- 各种数据库支持的注释
- sss
- 网页布局之---固定布局、流动布局、弹性布局
- FAFU - 1030 最短距离
- Scrum meeting当中的“鸡”和“猪”
- pushlet+内存数据库,完成在线交流
- WEP的四次握手过程
- grep 条件或
- Android工程JNI调用*.so文件加载
- PHP-redis中文文档
- 常见加密算法整理
- bootstrap中的alerts