POJ 1122 FDNY to the Rescue!
来源:互联网 发布:linux回到家目录 编辑:程序博客网 时间:2024/06/03 13:57
给出某些交叉点的距离,-1 表示无法到达。
然后给出火灾发生点 和 附近的消防局位置。
排列消防局 的 时间 与路径。
反向建图,以火灾出发点为起点做一次SPFA。
#include<cstdio>#include<cstring>#include<string>#include<queue>#include<algorithm>#include<queue>#include<map>#include<stack>#include<iostream>#include<list>#include<set>#include<cmath>#define INF 0x7fffffff#define eps 1e-6using namespace std;int n;struct lx{ int v,t;};vector<lx>g[21];bool vis[21];int path[21];int dis[21];void SPFA(int start){ for(int i=1;i<=n;i++) dis[i]=INF,vis[i]=0,path[i]=0; queue<int>q; vis[start]=1,dis[start]=0; q.push(start); while(!q.empty()) { int u=q.front();q.pop(); vis[u]=0; for(int j=0;j<g[u].size();j++) { int v=g[u][j].v; int t=g[u][j].t; if(dis[v]>dis[u]+t) { dis[v]=dis[u]+t; path[v]=u;// 记录路径 if(!vis[v]) { vis[v]=1; q.push(v); } } } }}struct node{ int Org,time;}l[21];bool cmp(node a,node b){ return a.time<b.time;}int main(){ while(scanf("%d",&n)!=EOF) { for(int i=1;i<=n;i++) { for(int j=1;j<=n;j++) { int t; scanf("%d",&t); if(i==j||t==-1)continue; lx now; now.v=i,now.t=t; g[j].push_back(now); } } int start,endcot=0; int thend[21]; scanf("%d",&start); getchar(); char str[101]; gets(str); int i=0; int c=0; while(str[i]==' ')i++; for(i=0;i<=strlen(str);i++) { while(str[i]>='0'&&str[i]<='9')c=c*10+str[i]-'0',i++; if(c!=0) thend[endcot++]=c,c=0; } SPFA(start); for( i=0;i<endcot;i++) l[i].Org=thend[i],l[i].time=dis[thend[i]]; sort(l,l+endcot,cmp); puts("OrgDestTimePath"); for( i=0;i<endcot;i++) { int v=l[i].Org; printf("%d%d%d",v,start,dis[v]); int tmp=v; while(path[tmp]!=0) printf("%d",tmp),tmp=path[tmp]; printf("%d\n",start); } }}
1 0
- 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||zoj 1053 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
- zoj 1053 && poj 1122 FDNY to the Rescue!
- POJ 1122 FDNY to the Rescue!(最短路径)
- POJ 1122 FDNY to the Rescue! 已被翻译
- poj1122 - FDNY to the Rescue!
- poj 1122 FDNY to the Rescue! (最短路+打印路径)
- ZPJ - 1053 FDNY to the Rescue!(最短路 Dijkstra),POJ 1122
- poj 1122 FDNY to the Rescue! 最短路径 dijkstra算法
- awk编程——数组
- DOM4J介绍与代码示例
- jsp forward 动作标签
- CTime以及其它时间差 DateTimePicker控件
- Matlab的imfilter函数用法
- POJ 1122 FDNY to the Rescue!
- Ogre 渲染过程
- Qt打开任意文件的方法
- windows 下mysql忘记root密码
- JQuery中$.ajax()方法参数详解
- WINCE 默认输入发设置
- x.509
- require.js学习总结
- linux 循环双链表(list.h)