HDU 2722(POJ 3653) Here We Go(relians) Again (建图,最短路Dijstra)
来源:互联网 发布:qq好友提取软件 编辑:程序博客网 时间:2024/06/08 11:15
题目链接:
http://acm.hdu.edu.cn/showproblem.php?pid=2722
http://poj.org/problem?id=3653
题意:给你n*m的矩形街区,给你街区中每条路的通过的方向和行驶速度(每一小段路的路程为2520),求从左上角到右下角的最短时间。
AC代码:
#include <stdio.h>#include <string.h>#define MAXN 500#define INF 0x3FFFFint map[MAXN][MAXN],dis[MAXN],vis[MAXN];int Dijkstra(int from,int to){int i,j,min,u;memset(vis,0,sizeof(vis));for(i=1;i<=to;i++) dis[i]=map[from][i]; dis[from]=0; for(i=1;i<=to;i++) { u=0; min=INF; for(j=1;j<=to;j++) { if(!vis[j]&&dis[j]<min) { min=dis[j]; u=j; } } vis[u]=1; for(j=1;j<=to;j++) { if(!vis[j]&&dis[u]+map[u][j]<dis[j])dis[j]=dis[u]+map[u][j]; } }return dis[to] ;}int main(){ int ans,x,y,h,s,i,j,n,m; while(scanf("%d %d",&n,&m)!=EOF) { if(n==0&&m==0) break; for(i=0;i<=(n+1)*(m+1);i++) { for(j=0;j<=(n+1)*(m+1);j++) map[i][j]=INF; } s=h=0; for(i=1;i<=2*n+1;i++) { if(i%2==1) { for(j=1;j<=m;j++) { char op; int v; scanf("%d %c",&v,&op); x=h*(m+1)+j; y=x+1; if(v==0) { map[x][y]=INF; map[y][x]=INF; } else if(op=='>') { map[x][y]=2520/v; map[y][x]=INF; } else if(op=='<') { map[x][y]=INF; map[y][x]=2520/v; } else { map[x][y]=2520/v; map[y][x]=2520/v; } } h++; } else { for(j=1;j<=m+1;j++) { char op; int v; scanf("%d %c",&v,&op); x=s*(m+1)+j; y=(s+1)*(m+1)+j; if(v==0) { map[x][y]=INF; map[y][x]=INF; } else if(op=='v') { map[x][y]=2520/v; map[y][x]=INF; } else if(op=='^') { map[x][y]=INF; map[y][x]=2520/v; } else { map[x][y]=2520/v; map[y][x]=2520/v; } } s++; } } ans=Dijkstra(1,(n+1)*(m+1)); if(ans==INF) printf("Holiday\n"); else printf("%d blips\n",ans); } return 0;}
0 0
- HDU 2722(POJ 3653) Here We Go(relians) Again (建图,最短路Dijstra)
- POJ 3653 & ZOJ 2935 & HDU 2722 Here We Go(relians) Again(最短路dijstra)
- poj 3653 Here We Go(relians) Again 最短路
- HDU 2722 Here We Go(relians) Again 最短路
- 【最短路】 HDU 2722 Here We Go(relians) Again
- HDU 2722Here We Go(relians) Again(dijk最短路)
- HDU 2722 Here We Go(relians) Again (SPFA+建图)
- 【最短路+dijkstra+spfa】杭电 hdu 2722 Here We Go(relians) Again
- hdu 2722 Here We Go(relians) Again(恶心读入+最短路floyd)
- POJ 3653 Here We Go (relians) Again
- Here We Go(relians) Again hdu 2722
- HDU 2722 Here We Go(relians) Again
- HDU 2722 Here We Go(relians) Again
- HDU 2722 Here We Go(relians) Again
- hdu 2722 Here We Go(relians) Again
- HDU-2722-Here We Go(relians) Again
- HDU 2722 Here We Go(relians) Again
- HDU 2722:Here We Go(relians) Again
- 数据结构概述 第二章
- C# CollectionBase源代码
- Lisp的非技术性吐槽
- 新入行程序员须知的8件事
- estore和小项目总结
- HDU 2722(POJ 3653) Here We Go(relians) Again (建图,最短路Dijstra)
- ARC与MRC的混合开发
- Sevlet-tomcat配置
- 一个简单的下载程序
- Cocos2d-x开发包的架构
- egrep的用法
- (58同城)2015笔试编程题
- POJ 1486 Sorting Slides(二分图必须边)
- 数据结构概述 第三章