HDU 1690 Bus System(多源最短路径)
来源:互联网 发布:淘宝手机端gif图 编辑:程序博客网 时间:2024/06/07 16:53
http://acm.hdu.edu.cn/showproblem.php?pid=1690
无穷大设置的不好,WA了3次,最后干脆改成-1过了。
#include <cstdio>#include <iostream>#include <cstring>using namespace std;const int maxn = 100+5;const __int64 inf=-1;__int64 map[maxn][maxn],dist[maxn][maxn];__int64 L[5],C[5];__int64 x[maxn];__int64 abss(__int64 x){ if(x<0) x=x*(-1); if(x<=L[1]) return C[1]; else if(x<=L[2]) return C[2]; else if(x<=L[3]) return C[3]; else if(x<=L[4]) return C[4]; return inf;}int n;void floyd(){ for(int i=1;i<=n;i++) for(int j=1;j<=n;j++){ if(i==j) dist[i][j]=0; else dist[i][j]=map[i][j]; } for(int k=1;k<=n;k++) for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) if(dist[i][k]!=-1&&dist[k][j]!=-1&&(dist[i][j]>dist[i][k]+dist[k][j]||dist[i][j]==-1)) dist[i][j]=dist[i][k]+dist[k][j];}int main(){ int T,m; scanf("%d",&T); for(int kas=1;kas<=T;kas++) { for(int i=1;i<5;i++) scanf("%I64d",&L[i]); for(int i=1;i<5;i++) scanf("%I64d",&C[i]); scanf("%d%d",&n,&m); for(int i=1;i<=n;i++){ scanf("%I64d",&x[i]); for(int j=1;j<i;j++) map[i][j]=map[j][i]=abss(x[i]-x[j]); } floyd(); printf("Case %d:\n",kas); while(m--) { int u,v; scanf("%d%d",&u,&v); if(dist[u][v]!=-1) printf("The minimum cost between station %d and station %d is %I64d.\n",u,v,dist[u][v]); else printf("Station %d and station %d are not attainable.\n",u,v); } } return 0;}
- HDU 1690 Bus System(多源最短路径)
- HDU 1690 多源最短路径 Bus System
- hdu 1690 Bus System Floyd 求最短路径
- [最短路径] HDU 1690 - Bus System
- HDU 1690 Bus System
- HDU 1690 Bus System
- hdu 1690 Bus System
- HDU 1690 Bus System
- HDU 1690 Bus System
- hdu 1690 Bus System
- hdu 1690 Bus System
- HDU 1690 Bus System.
- hdu-1690 Bus System
- hdu 1690 Bus System
- hdu 1690 Bus System
- HDU-1690-Bus System
- HDU-1690-Bus System
- HDU 1690:Bus System
- PHP自学之路-----走进数组及相关数组函数
- 循环(迭代/递推)与递归
- delphi根据进程ID获取进程路径
- setDesignResolutionSize 到竖屏下面就缩放尺寸不对的问题
- 身份认证防止重放攻击的challenge-response方法
- HDU 1690 Bus System(多源最短路径)
- AsyncTask 学习翻译并总结
- eclipse中关键字,类加载提示快捷键设置
- Bellman-Ford算法的详解
- 对比PeekMessage与GetMessage
- Wireless tools for Linux 介绍 使用 交叉编译 及 移植wireless tools for liunx
- Java链接mysql
- 一 使用JavaScript
- 浅谈国家自然科学基金成功申请的方法