hdu 2112 HDU Today(最短路)
来源:互联网 发布:方舟生存进化优化 2016 编辑:程序博客网 时间:2024/06/03 05:07
AC 代码
#include<stdio.h>#include<iostream>#include<string.h>#define INF 100000000using namespace std;int Map[200][200],dis[200],count;int d(){ bool flag[200]; int i,j,D; for(i=0; i<count; i++) dis[i]=Map[0][i]; memset(flag,0,sizeof(flag)); dis[0] = 0; int n=count-1; while(n--) { int min = INF; for(i=0; i<count; i++) if(!flag[i]&&dis[i]<min) { min = dis[i]; D = i; } flag[D] = 1; for(i=0; i<count; i++) { if(!flag[i]&&dis[i]>dis[D]+Map[D][i]) dis[i] = dis[D] + Map[D][i]; } } return dis[1];}int main(){ char str1[30],str2[30],name[200][30],Begin[30],End[30]; int i,j,x,y,n,t; while(scanf("%d",&n) && n!=-1) { for(i=0; i<=155; i++) for(j=0; j<=155; j++) Map[i][j]= INF ; getchar(); scanf("%s %s",name[0],name[1]); getchar(); count = 2; for(i=1; i<=n; i++) { scanf("%s %s %d",str1,str2,&t); for(j=0; j<count; j++) { if(strcmp(name[j],str1)==0) { x=j; break; } } if(j==count) { strcpy(name[count++],str1); x=count-1; } for(j=0; j<count; j++) { if(strcmp(name[j],str2)==0) { y=j; break; } } if(j==count) { strcpy(name[count++],str2); y=count - 1; } if(Map[x][y]>t) Map[x][y]=t; if(Map[y][x]>t) Map[y][x]=t; } if(strcmp(name[0],name[1])==0) cout << "0" << endl; else { int ans = d(); if(ans>=INF) printf("-1\n"); else printf("%d\n",ans); } } return 0;}
0 0
- HDU 2112 HDU Today(最短路)
- hdu 2112 HDU Today(最短路)
- HDU 2112HDU Today (最短路)
- hdu 2112 HDU Today (最短路)
- 【HDU】-2112-HDU Today(最短路)
- HDU 2112 HDU Today(最短路)
- HDU Today 最短路
- hdu 2112 HDU Today( 最短路)
- hdu 2112 HDU Today 最短路
- hdu 2112HDU Today 最短路+map
- HDU-2112 HDU Today 最短路
- 【hdu 2112】 HDU Today ( 最短路 Dijkstra)0x3f3f3f3f
- HDU 2112 HDU Today(最短路,dijkstra)
- hdu 2112 HDU Today(最短路+字典树)
- hdu 2112 HDU Today 最短路(Dijkstra算法)
- HDU 2112HDU Today(dijk最短路+map)
- HDU-2112 HDU Today(最短路[Dijkstra])
- HDU 2112 HDU Today (最短路---dijkstra+map函数)
- .NET技术+25台服务器怎样支撑世界第54大网站
- oracle 动态sql select into
- POJ 2533 LIS模板
- Gallery实现快速拖动只滑动一页的解决办法
- 数字游戏
- hdu 2112 HDU Today(最短路)
- ASP.NET开发大全第7章.数据库与ADO.NET基础
- Cocoa和Objective-c特性
- 深入理解HTTP Session
- (转)递归树求递归算法的时间复杂度
- HashSet 中储存先判断对象的hash值 如果一样 在调用 对象equals方法判断是否是同一个对象
- cocos2d-x Json解析
- Android设计模式系列--工厂方法模式
- Effective C# Item24:声明式编程优于命令式编程