poj 1122||zoj 1053 FDNY to the Rescue!(最短路)
来源:互联网 发布:c语言关键字有哪些 编辑:程序博客网 时间:2024/06/02 00:11
poj上过了,但zoj上SF到吐。
求路过的大牛指点一二。
#include<iostream>#include <cstdio>#include <string.h>#include<stdlib.h>#define inf 1000000using namespace std;typedef struct fd{int org,dest,time,path[25];}fd;int cmp( const void *a , const void *b ) { struct fd *c = (fd *)a; struct fd *d = (fd *)b; return c->time - d->time; }int main(){int T,N,M,i,k,j,v0,u,temp;fd ff[25];int a[25][25],S[25],pre[25],min[25],shortest[25];cin>>T;while(T--){cin>>N;for(i=1;i<=N;i++)for(j=1;j<=N;j++){cin>>a[i][j];if(a[i][j]==-1) a[i][j]=inf;}int len=0;cin>>M;while(~scanf("%d",&v0)){ff[len].dest=M;ff[len].time=0;ff[len].org=v0;ff[len].path[v0]=-1;for(i=1;i<=N;i++){S[i]=0;min[i]=a[v0][i];if(i!=v0&&min[i]<inf) pre[i]=v0;else pre[i]=-1;}S[v0]=1;min[v0]=0;for(i=1;i<=N;i++){u=v0,temp=inf;for(j=1;j<=N;j++){if(!S[j]&&temp>min[j])u=j,temp=min[j];}S[u]=1;for(k=1;k<=N;k++){if(!S[k]&&a[u][k]<inf&&min[k]>min[u]+a[u][k])pre[k]=u,min[k]=min[u]+a[u][k];}}ff[len].time=min[M];memset(shortest,0,sizeof(shortest));k=0;shortest[k]=M;while(pre[shortest[k]]!=-1){k++;shortest[k]=pre[shortest[k-1]];}for(i=0;i<=k;i++)ff[len].path[i]=shortest[k-i];len++;}qsort(ff,len,sizeof(ff[0]),cmp);printf("Org Dest Time Path\n");for(i=0;i<len;i++){printf("%d\t%d\t%d\t",ff[i].org,ff[i].dest,ff[i].time);for(j=0;ff[i].path[j]!=M;j++)printf("%d\t",ff[i].path[j]);printf("%d\n",M);}}return 0;}
- poj 1122||zoj 1053 FDNY to the Rescue!(最短路)
- poj 1122 FDNY to the Rescue! 最短路
- POJ--1122--FDNY to the Rescue!【最短路】
- zoj 1053 && poj 1122 FDNY to the Rescue!
- ZPJ - 1053 FDNY to the Rescue!(最短路 Dijkstra),POJ 1122
- poj 1122 FDNY to the Rescue! (最短路+打印路径)
- POJ 1122 FDNY to the Rescue!(最短路径)
- zoj 1053 FDNY to the Rescue!
- ZOJ-1053 FDNY to the Rescue!
- Poj 1122 FDNY to the Rescue
- POJ:1122 FDNY to the Rescue!
- poj 1122 FDNY to the Rescue!
- POJ 1122 FDNY to the Rescue!
- poj 1122 FDNY to the Rescue!
- POJ 1122 FDNY to the Rescue!
- poj 1122 FDNY to the Rescue! 最短路径 dijkstra算法
- poj 1122 FDNY to the Rescue! (dijkstra)
- POJ 1122 FDNY to the Rescue! 反向dijkstra
- Ext在IE9上报错:对象不支持“createContextualFragment”属性或方法
- 《与Java相恋》(高级篇)一简单的java web应用程序部署
- Android开发之道(1)搭建开发环境以HelloWorld例程
- 编写程序时键盘的使用技巧:
- 公元二零一二之个人规划
- poj 1122||zoj 1053 FDNY to the Rescue!(最短路)
- C++的CLR程序与C#程序对比(2)
- Linux-world-2012-January->9 (dnw2_for_linux(ubuntu)successful version)
- Linux+Apache+Mysql+PHP安装笔记
- 深入浅出linux之总线和设备(platform总线)
- 嵌入式开发:中断优先级的重要性
- 我的sourceinsight字体设置
- Azure Storage Note
- Visual Studio 11开发指南(1) Visual Studio 11简介与新特性