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 ...
随机推荐
- Struts2的Stack Context和ValueStack
1.提到Struts2的传值功能时,经常会见到Stack Context和ValueStack等概念,那么它们到底是什么,有什么作用呢. ValueStack(值栈):Struts2将OGNL上下文设 ...
- Delphi 把一个ICO转换为BMP
// 方法1 var Icon : TIcon; Bitmap : TBitmap; begin Icon := TIcon.Create; Bitmap := TBitmap.Create; Ico ...
- zookeeper watch 节点
zjtest7-redis:/root/zk# cat a1.pl use ZooKeeper; use AnyEvent; use AE; use Data::Dumper; use IO::Soc ...
- Item with the same id "98" already exist
在magento项目中多次遇到这样一个错误: Item (Bluecom_Onefieldusername_Model_Customer) with the same id "98" ...
- Pods 更新后提示Bundle资源找不到
http://www.oschina.net/question/101347_2159145
- ER图与UML图
ER图:实体-联系图(Entity-Relation Diagram)用来建立数据模型,在数据库系统概论中属于概念设计阶段,ER图提供了表示实体(即数据对象).属性和联系的方法,用来描述现实世界的概念 ...
- Excel中公式的绝对引用和相对引用单元格
在Excel的表格中,非常常用的就是公式里的绝对引用和相对引用了,具体情况请看下列表格吧. 步骤1 打开做好的excel表格.公式中的相对单元格引用是基于包含公式和单元格引用的单元格的相对位置,若公式 ...
- Android开发问题汇总(持续更新)
在Android开发中,总会有一些很小的问题.由于我们的不仔细,很容易忽略掉,从而导致在该问题上花费了很多的时间,造成工作进度的延迟. 为此,在这里做一下记录,避免再次浪费许多时间在这些问题上. 1. ...
- Lua中强大的元方法__index详解
今天要来介绍比较好玩的内容:__index元方法 我是备胎,记得回头看看 咳咳,相信每一位女生都拥有或者不知不觉中拥有了一些备胎,啊!当然,又或许是成为过别人的备胎. 没有备胎的人,就不是完整的人生. ...
- Matlab基础知识
一.常用命令:普通的如cd.ls和linux下一样 clc:清除工作窗口中的所有显示内容 clf:清除图形窗口 whos:列出当前工作空间中所有变量,以及它们的名字.尺寸(比如一个矩阵或数组的行列维数 ...