find the mincost route(最小环,最短路,floyd)
find the mincost route
Time Limit: 1000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 3425 Accepted Submission(s): 1397
州有N个景区,景区之间有一些双向的路来连接,现在8600想找一条旅游路线,这个路线从A点出发并且最后回到A点,假设经过的路线为
V1,V2,....VK,V1,那么必须满足K>2,就是说至除了出发点以外至少要经过2个其他不同的景区,而且不能重复经过同一个景区。现在
8600需要你帮他找一条这样的路线,并且花费越少越好。
接下来的M行里,每行包括3个整数a,b,c.代表a和b之间有一条通路,并且需要花费c元(c <= 100)。
1 2 1
2 3 1
1 3 1
3 3
1 2 1
1 2 3
2 3 1
It's impossible.
#include<stdio.h>
#include<string.h>
#define MIN(x,y)(x<y?x:y)
const int INF=0x3f3f3f;
const int MAXN=;
int map[MAXN][MAXN],dis[MAXN][MAXN],anser;
int N,M;
void initial(){
for(int i=;i<=;i++)
for(int j=;j<=;j++)
if(i-j)map[i][j]=INF;
else map[i][j]=;
}
void floyd(){
for(int i=;i<=N;i++)
for(int j=;j<=N;j++)
dis[i][j]=map[i][j];
anser=INF;
for(int k=;k<=N;k++){
for(int i=;i<=N;i++)
for(int j=;j<=N;j++)
if(i!=j&&i!=k&&j!=k)
anser=MIN(anser,dis[i][j]+map[j][k]+map[k][i]);
/*if(anser>dis[i][j]+map[j][k]+map[k][i]){
printf("dis[%d][%d]=%d\n",i,j,dis[i][j]);
printf("map[%d][%d]=%d\n",j,k,map[j][k]);
printf("map[%d][%d]=%d\n",k,i,map[k][i]);
}*/
for(int i=;i<=N;i++)
for(int j=;j<=N;j++)
dis[i][j]=MIN(dis[i][j],dis[i][k]+dis[k][j]);//弄成maple错了半天。。。。
}
if(anser==INF)puts("It's impossible.");
else printf("%d\n",anser);
}
int main(){
int a,b,c;
while(~scanf("%d%d",&N,&M)){
initial();
while(M--){
scanf("%d%d%d",&a,&b,&c);
if(c<map[a][b])map[a][b]=map[b][a]=c;
}
floyd();
}
return ;
}
find the mincost route(最小环,最短路,floyd)的更多相关文章
- hdu 1599 find the mincost route 最小环
题目链接:HDU - 1599 杭州有N个景区,景区之间有一些双向的路来连接,现在8600想找一条旅游路线,这个路线从A点出发并且最后回到A点,假设经过的路线为V1,V2,....VK,V1,那么必须 ...
- hdoj 1599 find the mincost route【floyd+最小环】
find the mincost route Time Limit: 1000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/O ...
- HDU 1599 find the mincost route(floyd求最小环 无向图)
传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1599 find the mincost route Time Limit: 1000/2000 MS ...
- hdu 1599 find the mincost route(无向图的最小环)
find the mincost route Time Limit: 1000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/O ...
- HD1599 find the mincost route(floyd + 最小环)
题目链接 题意:求最小环 第一反应时floyd判断,但是涉及到最少3个点,然后就不会了,又想的是 双联通分量,这个不知道为什么不对. Floyd 判断 最小环 #include <iostrea ...
- hdu 1599 find the mincost route floyd求无向图最小环
find the mincost route Time Limit: 1000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/O ...
- hdu1599 find the mincost route floyd求出最小权值的环
find the mincost route Time Limit: 1000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/O ...
- [hdu P1599] find the mincost route
[hdu P1599] find the mincost route 杭州有N个景区,景区之间有一些双向的路来连接,现在8600想找一条旅游路线,这个路线从A点出发并且最后回到A点,假设经过的路线为V ...
- hdu 1599 find the mincost route (最小环与floyd算法)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1599 find the mincost route Time Limit: 1000/2000 MS ...
随机推荐
- In Depth : Android Boot Sequence / Process
In Depth : Android Boot Sequence / Process What happened when I press power on button in my Android ...
- js打开新窗口的两种方式
1.超链接<a href="http://www.jb51.net" title="脚本之家">Welcome</a>等效于js代码wi ...
- 转:JavaScript函数式编程(一)
转:JavaScript函数式编程(一) 一.引言 说到函数式编程,大家可能第一印象都是学院派的那些晦涩难懂的代码,充满了一大堆抽象的不知所云的符号,似乎只有大学里的计算机教授才会使用这些东西.在曾经 ...
- Is life always hard?
原文来自我的独立blog: http://www.yuanyong.org/blog/midnightsun/is-life-always-hard 和两个朋友聊天. 小L在考研,打电话过去的时候小L ...
- Introducing Regular Expressions 学习笔记
Introducing Regular Expressions 读书笔记 工具: regexbuddy:http://download.csdn.net/tag/regexbuddy%E7%A0%B4 ...
- 网易云课堂_C语言程序设计进阶_第三周:结构:结构、类型定义、联合
3.1 枚举 3.2 结构 3.3 类型定义 3.1 枚举 枚举是一种用户定义的数据类型,它用关键字enum以如下语法来表明: enum 枚举类型名字{名字0,...,名字n}; 枚举类型名字通常并不 ...
- 怎样在小方框上打对号 小方框内打对勾 word 方框打对勾
在word中做选择时,非常多人遇到须要在小方框上打对勾而不知怎样做,现将可行的各种方法总结例如以下: 1:直接找到一个做好的,保存为图片,在须要的时候插入它: 2:插入文本框,然后边框选择为实线,在文 ...
- update慢怎样处理?
update慢: 1.表的pctfree參数设置? 2.运行计划用索引还是全表扫? 3.SQL语句写法问题? 4.update慢还是commit慢? 5.更新多少条数据? 6.表是否频繁update造 ...
- java.lang.IllegalStateException: Target host must not be null, or set in parameters. scheme=null, host=null, path=Aict/listPagedAict.action
原因:请求的URL地址不完整,没有找到host. 排查解决:发现HTTP请求的URL少加了项目名,导致URL地址不完整.
- uva12589
题目大意:给n(n<=50)个向量(xi,yi) (0<=xi<=yi<=50),选出其中k(1<=k<=n)个,从(0,0)点开始,依次首尾相连,求此k个向量与x ...