hdu1599
来源:互联网 发布:linux怎么退出全屏 编辑:程序博客网 时间:2024/04/30 15:23
链接:点击打开链接
题意:有一些景点,看其中能从一个景点走至少要经过2个其他不同的景区,而且不能重复经过同一个景区,每条路线需要一些花费,找出一条花费最少的路线,如果不能输出It's impossible.
代码:
#include <iostream>#include <stdio.h>#include <string.h>#include <algorithm>#define maxx 99999999using namespace std;int dis[105][105],s[105][105];int n,m;int floyd(){ int i,j,k,ans; ans=maxx; for(k=1;k<=n;k++){ for(i=1;i<k;i++) for(j=i+1;j<k;j++) //求的是可能经过k-1的i到j的花费最小值+s[j][k]+s[k][i],也就是从i开始 ans=min(ans,dis[i][j]+s[j][k]+s[k][i]); //可能成环的最小值 for(i=1;i<=n;i++) for(j=1;j<=n;j++) dis[i][j]=min(dis[i][j],dis[i][k]+dis[k][j]); } //求的是可能经过k的i到j的花费最小值 return ans;}int main(){ //就是求无向图最小环问题 int i,j,a,b,c,temp; while(scanf("%d%d",&n,&m)!=EOF){ for(i=1;i<=n;i++) for(j=1;j<=n;j++) dis[i][j]=s[i][j]=maxx; for(i=1;i<=m;i++){ scanf("%d%d%d",&a,&b,&c); if(s[a][b]>c){ //这个要注意,他可能有重边,也就是同样的路径可能有两个不同的值 dis[a][b]=dis[b][a]=c; s[a][b]=s[b][a]=c; } } temp=floyd(); if(temp<maxx) printf("%d\n",temp); else printf("It's impossible.\n"); } return 0;}
0 0
- HDU1599
- hdu1599
- hdu1599
- hdu1599
- HDU1599
- hdu1599+floyd最小环
- hdu1599 最小环问题
- HDU1599 find the mincost route
- hdu1599 find the mincost route
- hdu1599 floyd 求最小环
- hdu1599 find the mincost route
- hdu1599(floyd算法讲解)
- hdu1599 find the mincost route
- 最小环 hdu1599 Floyd算法
- HDU1599:find the mincost route
- hdu1599 find the mincost route
- [hdu1599]find the mincost route
- hdu1599——find the mincost route
- 利用environment文件配置heat模板参数
- 黑马程序员-----基本语法(2)
- http下载文件,中文文件名在firefox下编码问题
- 5款免费Windows远程连接Linux桌面软件(VNC客户端)
- 黑马程序员—其他类
- hdu1599
- java集合深入学习--并发集合
- Introduction to Java Programming编程题5.14<计算数列>
- 递归和迭代的区别
- hdu1863畅通工程(最小生成树)
- Window下使用Xshell连接VirtualBox中CentOS SSH最佳实践
- Mac 安装jabberd 和adium通信
- freerdp和xrdp资料
- 使用div创建textArea无滚动条高度自适应