poj 2607 Fire Station
来源:互联网 发布:万德数据库打不开 编辑:程序博客网 时间:2024/05/21 17:59
城市要新建一个消防站,减少居民离最近的消费站之间的距离。
输入文本,第一行有两个正整数f,i。f表示消防站的数目,i表示交叉路口的数目。接下来给出f行,每行给出一个消防站的路口序号,接下来有若干行,每行有3个正整数,格式为A,B,L,A B表示路口,L表示路段的长度。道路是双向的。
对于每组数据输出一个n,n的含义是新的消防站所在的交叉路口的序号,选择n可以使得所有交叉路口到最近的一个消防站的距离中的最大值最小,而且n是满足条件的交叉路口序号中序号最小的。
#include<iostream>#include<cstdio>#include<cstring>#include<string>using namespace std;const int fN = 150;const int iN = 550;const int INF = 0x3f3f3f3f;int main(){ int f,n; int Fire[fN]; int Map[iN][iN]; scanf("%d %d",&f,&n); memset(Map,0x3f,sizeof(Map)); for(int i = 0 ; i < f ; i++) { scanf("%d",&Fire[i]); } int a,b,c; for(int i = 1 ; i <= n ; i++) { Map[i][i] = 0; } while(~scanf("%d %d %d",&a,&b,&c)) { Map[a][b] = min(Map[a][b],c); Map[b][a] = Map[a][b]; } for(int k = 1 ; k <= n ; k++) { for(int i = 1 ; i <= n ; i++) { for(int j = 1 ; j <= n ; j++) { if(Map[i][j] > Map[i][k] + Map[k][j]) { Map[i][j] = Map[i][k] + Map[k][j]; } } } } int Min[iN]; memset(Min,0x3f,sizeof(Min)); for(int i = 1 ; i <= n ; i++)//每个点到最近的消防站的最小值 { for(int j = 0 ; j < f ; j++) { int cur = Fire[j]; if(Map[i][cur] < Min[i] ) { Min[i] = Map[i][cur]; } } } int Maxdis = INF; int ans; for(int i = 1 ; i <= n ; i++)//枚举每个点作为消防站 { int tempDis = 0; for(int j = 1 ; j <= n ; j++)//tempdis为每个点建立消防站后所有点到最近消防站的最大距离 { int k; if(Map[i][j] < Min[j]) { k = Map[i][j]; } else { k = Min[j]; } if(k > tempDis) { tempDis = k; } } if(tempDis < Maxdis)//使得这个最大值最小 { Maxdis = tempDis; ans = i; } } cout<<ans<<endl; return 0;}
0 0
- POJ 2607 Fire Station
- poj 2607 Fire Station
- poj 2607 Fire Station
- POJ 2607 Fire Station
- poj 2607 Fire Station
- poj 2607 Fire Station(floyd)
- POJ 2607 / ZOJ 1857 /NYOJ210 Fire Station
- POJ 2607 ZOJ 1857 Fire Station
- ZOJ 1857 && POJ 2607 Fire Station【SPFA】
- POJ 2607 Fire Station(floyd)
- ZOJ-1857(POJ-2607) Fire Station
- poj 2607 Fire Station (spfa)
- POJ 2607 Fire Station(Floyd)
- POJ 2607 Fire Station 消防站
- POJ 2607 / ZOJ 1857 Fire Station (临接表+spfa)
- zoj 1857 || poj 2607 Fire Station(纠结!!!)
- Fire Station
- Fire Station
- Android 嵌套布局导致的Exception: java.lang.ClassCastException
- Linux查看CPU和内存使用情况
- 黑马程序员-Foundation框架
- 数据结构_求二叉树的宽度_C语言源代码
- hkhj
- poj 2607 Fire Station
- MATLAB画图常用调整代码
- Java框架概述
- 三闾大夫接啊拉萨的风加拉大事掘坟
- Core Animation链接专题
- hdu 1232 畅通工程(数据结构:并查集)
- 学习杂记
- UML 活动图
- Reorder List Java