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 ...
随机推荐
- QueryString和BASE64
加号(+)是BASE64编码的一部分,而加号在QueryString中被当成是空格.因此,当一个含有BASE64编码的字符串直接作为URL的一部分时,如果其中含有加号,则使用QueryString读取 ...
- WampServer下如何实现多域名配置
原文:WampServer下如何实现多域名配置 之前在学习跨域的时候,我写过一篇叫做WampServer下使用多端口访问的文章,默认的 localhost 采用的是 80 端口,能使用多端口访问的核心 ...
- CC++初学者编程教程(4) 安装Oracle12c于Windows Sever2012
我们开启虚拟机 Windows Sever2012启动中. 3.看到WindowsSever2012的桌面. 我们解压缩两个文件, winx64_12c_database_1of2.zip,winx6 ...
- [11-3] Gradient Boosting regression
main idea:用adaboost类似的方法,选出g,然后选出步长 Gredient Boosting for regression: h控制方向,eta控制步长,需要对h的大小进行限制 对(x, ...
- 10-3[RF] feature selection
main idea: 计算每一个feature的重要性,选取重要性前k的feature: 衡量一个feature重要的方式:如果一个feature重要,则在这个feature上加上noise,会对最后 ...
- ios常用的框架(源自知乎上的回答)
首先,学习这类开源项目的主要目的是为了实现产品汪需求,如果不是这个目的,完全可以看Explore GitHub,当前最火的开源项目都在这里,当然你需要过滤一下语言. 好了,介绍几个希望能帮助到你. 普 ...
- LINQ查询操作符 LINQ学习第二篇[转]
一.投影操作符 1. Select Select操作符对单个序列或集合中的值进行投影.下面的示例中使用select从序列中返回Employee表的所有列: using (NorthwindDataCo ...
- IOS学习笔记07---C语言函数-printf函数
IOS学习笔记07---C语言函数-printf函数 0 7.C语言5-printf函数 ------------------------- ----------------------------- ...
- 【Andord真】SlideMenu+ViewPagerIndictor双滑动边栏+滑动导航条
采取SlideMenu达到的效果侧边栏: 间 setContentView是设置主背景的布局 setBehindContentView是设置左边菜单的布局 setSecondaryMenu是设置右边的 ...
- IT人员----怎么把电脑窗口设置成淡绿色
大夫建议电脑屏幕不要用白色,因为白色对眼睛的刺激是最大的.像我们这样整天对着电脑,也应该注意一下.其实,只要稍微设置一下,就能让你电脑上的窗口从白花花的颜色变成淡淡的绿色. 设置方法:打开控制面板中的 ...