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 ...
随机推荐
- OpenGL ES 三种类型 uniform attribute varying
1.uniform变量 uniform变量是外部application程序传递给(vertex和fragment)shader的变量.因此它是application通过函数glUniform**()函 ...
- Struts2命名空间问题
警告: No configuration found for the specified action: '/myNameSpace/login.action' in names 今天花了点时间把st ...
- 计算机图形学--旋转变换(java)
import java.awt.Color; import java.awt.Frame; import java.awt.Graphics; import java.awt.event.Window ...
- fieldset 使用小案例
有初学者问到如何做出如下页面: 对应的代码如下: <fieldset> <legend>★审核状态</legend> <input name="st ...
- 本地化SilverLight应用程序(多语言支持)
原文 http://www.cnblogs.com/seaworm/archive/2010/11/30/1892325.html 利用资源文件(Resources File)使SilverLight ...
- javascript小知识1 this的用法
函数的应用: <!DOCTYPE html> <html lang="en"> <head> <meta charset="UT ...
- Android消息推送的服务端
2.Android消息推送 MQTT服务器采用mosquito http://mosquitto.org/ PHP管理包采用phpmqttclient:https://github.com/toku ...
- Eclipse快捷键大全(一)
Eclipse快捷键大全(一) 常用(系统默认): 1.Format (自动排版) : Ctrl+Shift+F 2.Organize Imports (自动导入) : Ctrl+Shift+O 3. ...
- C-Free 您不能使用调试解决方案
什么时候C-Free 当您调试 找不到gdb.exe解决方案 http://www.programarts.com/ C-Free 官方网站 下载Mingw或者其他编译器 版权声明:本文博主原创文章. ...
- UIViewController、UINavigationController与UITabBarController的整合使用
UINavigationController与UITabBarController是iOS开发中最常用的两种视图控制器,它们都属于UIViewController的子类,继承关系如下: @interf ...