poj 3653 Here We Go(relians) Again 最短路
来源:互联网 发布:java 命令行打包 编辑:程序博客网 时间:2024/06/08 19:12
题意:
给一个城市网络,有n*m个街区组成,每条路所花时间易求,要算从城市左上角到右下叫的最短时间。
分析:
简单最短路,只是输入有点恶心。
代码:
//poj 3653//sepNINE#include <iostream>#include <queue>using namespace std;const int maxN=512;const int maxM=2048;int n,m,e,head[maxN],inq[maxN],d[maxN];struct Edge{int v,w,next;}edge[maxM];void addEdge(int u,int v,int w){edge[e].v=v;edge[e].w=2520/w;edge[e].next=head[u];head[u]=e++;}void spfa(){int i;queue<int> Q;for(i=0;i<n;++i) d[i]=INT_MAX;inq[0]=1;d[0]=0;Q.push(0);while(!Q.empty()){int u=Q.front();Q.pop();inq[u]=0;for(i=head[u];i!=-1;i=edge[i].next){int v=edge[i].v,w=edge[i].w;if(d[v]>d[u]+w){d[v]=d[u]+w;if(!inq[v]){inq[v]=1;Q.push(v);}}}}if(d[n-1]==INT_MAX)printf("Holiday\n");elseprintf("%d blips\n",d[n-1]);}int main(){while(scanf("%d%d",&n,&m)==2&&n){e=0;memset(head,-1,sizeof(head));memset(inq,0,sizeof(inq));int i,j,x;char tmp[8],c;for(i=0;i<2*n+1;++i){if(i%2==0)for(j=0;j<m;++j){scanf("%d%s",&x,tmp);c=tmp[0];int u=i/2*(m+1)+j;int v=i/2*(m+1)+j+1;if(x==0)continue;else if(c=='*'){addEdge(u,v,x);addEdge(v,u,x);}else if(c=='>')addEdge(u,v,x);else if(c=='<')addEdge(v,u,x);}elsefor(j=0;j<m+1;++j){scanf("%d%s",&x,tmp);c=tmp[0];int u=(i/2)*(m+1)+j;int v=(i/2+1)*(m+1)+j;if(x==0)continue;else if(c=='*'){addEdge(u,v,x);addEdge(v,u,x);}else if(c=='v')addEdge(u,v,x);else if(c=='^')addEdge(v,u,x);}} n=(n+1)*(m+1);spfa();}return 0;}
0 0
- poj 3653 Here We Go(relians) Again 最短路
- 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
- Here We Go(relians) Again
- 【最短路+dijkstra+spfa】杭电 hdu 2722 Here We Go(relians) Again
- HDU 2722Here We Go(relians) Again(dijk最短路)
- hdu 2722 Here We Go(relians) Again(恶心读入+最短路floyd)
- 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
- Android动画之Tween动画实现
- Android AVD 没有键盘
- TCP协议的三次握手和四次挥手的整理
- 根据文字自定义Label和Cell高度
- div设置边框,微软字体雅黑
- poj 3653 Here We Go(relians) Again 最短路
- 黑马程序员——NSDictionary和NSDate的使用
- Java实现文件压缩与解压[zip格式,gzip格式]
- uva 10269(最短路径)
- IIS 5.x 与 ASP.NET
- 赞助
- Servlet生命周期中的service方法探究
- div+css布局,清除浮动
- 师傅对新人的建议