find the mincost route
来源:互联网 发布:无奈 知乎 编辑:程序博客网 时间:2024/05/19 08:45
find the mincost route
Time Limit: 1000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 4289 Accepted Submission(s): 1721
Problem Description
杭州有N个景区,景区之间有一些双向的路来连接,现在8600想找一条旅游路线,这个路线从A点出发并且最后回到A点,假设经过的路线为V1,V2,....VK,V1,那么必须满足K>2,就是说至除了出发点以外至少要经过2个其他不同的景区,而且不能重复经过同一个景区。现在8600需要你帮他找一条这样的路线,并且花费越少越好。
Input
第一行是2个整数N和M(N <= 100, M <= 1000),代表景区的个数和道路的条数。
接下来的M行里,每行包括3个整数a,b,c.代表a和b之间有一条通路,并且需要花费c元(c <= 100)。
接下来的M行里,每行包括3个整数a,b,c.代表a和b之间有一条通路,并且需要花费c元(c <= 100)。
Output
对于每个测试实例,如果能找到这样一条路线的话,输出花费的最小值。如果找不到的话,输出"It's impossible.".
Sample Input
3 31 2 12 3 11 3 13 31 2 11 2 32 3 1
Sample Output
3It's impossible.
Author
8600
之前做过的题了比赛了时候还是没做出来不知道为什么写的最短路老是出错
这个题直接看代码一看就懂了
#include <cstdio>#include <algorithm>using namespace std;int n,m;int Map1[101][101];int Map2[101][101];int ans;void Floyd(){ for(int i=1;i<=n;i++){ for(int j=1;j<=n;j++) Map2[i][j]=Map1[i][j]; } for(int k=1;k<=n;k++){ for(int i=1;i<=n;i++){ for(int j=1;j<=n;j++){ if(i!=j&&j!=k&&i!=k){ ans=min(Map1[i][j]+Map2[j][k]+Map2[k][i],ans);//不经过k点时的最小环 // printf("%d-%d-%d-%d--%d\n",i,j,k,i,ans); } } } for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) Map1[i][j]=min(Map1[i][j],Map1[i][k]+Map1[k][j]); }}int main(){ while(scanf("%d %d",&n,&m)!=EOF){ for(int i=1;i<=100;i++){ for(int j=1;j<=100;j++){ if(i==j) Map1[i][j]=0; else Map1[i][j]=10000; } } while(m--){ int a,b,c; scanf("%d %d %d",&a,&b,&c); if(Map1[a][b]>c) Map1[a][b]=Map1[b][a]=c; } ans=10000; Floyd(); if(ans==10000) printf("It's impossible.\n"); else printf("%d\n",ans); } return 0;}
0 0
- find the mincost route
- find the mincost route
- find the mincost route
- find the mincost route
- find the mincost route
- find the mincost route
- find the mincost route
- HDU1599 find the mincost route
- hdu1599 find the mincost route
- hdu1599 find the mincost route
- hdu1599 find the mincost route
- Hdoj find the mincost route
- find the mincost route hdoj1599
- HDU1599:find the mincost route
- HDU_1599 find the mincost route
- find the mincost route HDU
- hdu1599 find the mincost route
- [hdu1599]find the mincost route
- js this 的用法
- Network学习11_Pcap包拆分工具pkt2flow介绍
- 数据结构实验之查找五:平方之哈希表
- HDU 1718 Rank
- 开发中的一些注意点
- find the mincost route
- Android开发的四大组件
- iOS Anti-Debug
- TCP三次握手与四次挥手
- 阶段性小结
- #cocos2dx3.0打包apk
- 华为OJ——求最大连续bit数
- Jar mismatch!Fix your dependencies异常
- 欢迎使用CSDN-markdown编辑器