poj1860 Currency Exchange(flody)
来源:互联网 发布:淘宝网兼职怎么做 编辑:程序博客网 时间:2024/05/17 20:27
题目给出了有向图的邻接表,求哪个点到其他所有点的距离之和最小,以及该点到其他点的最短距离的最大值。
才100个点,用flody跑出所有点对的最短距离,然后O(n)一遍一遍的找。
#include<iostream>#include<cstdio>#include<string>#include<cstring>#include<algorithm>#include<queue>#include<cmath>#include<cmath>#include<map>#include<set>#include<stack>#include<vector>#include<climits>#define maxn 200#define LL long longusing namespace std;int _map[maxn][maxn];LL sum[maxn];bool flody(int &pos,int &len,int n,int MAX){ 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]; } } } memset(sum,0,sizeof(sum)); for(int i=1;i<=n;++i) { for(int j=1;j<=n;++j) { if(_map[i][j]<MAX ) { sum[i]+=_map[i][j]; } else { sum[i]=-1; break; } } } LL mmin=LLONG_MAX; bool flag=false; for(int i=1;i<=n;++i) { if(sum[i]!=-1 && sum[i]<mmin) { flag=true; mmin=sum[i]; pos=i; } } for(int i=1;i<=n;++i) { if(i==pos) continue; len=max(len,_map[pos][i]); } return flag;}int main(){ int n; while(scanf("%d",&n),n!=0) { memset(_map,0x3f,sizeof(_map)); int MAX=_map[0][0]; for(int i=0;i<=n;++i) _map[i][i]=0; for(int i=1;i<=n;++i) { int m; scanf("%d",&m); for(int j=0;j<m;++j) { int v,w; scanf("%d%d",&v,&w); _map[i][v]=w; } } int pos,len=0; bool flag=flody(pos,len,n,MAX); if(flag) printf("%d %d\n",pos,len); else printf("disjoint\n"); }}
0 0
- poj1860 Currency Exchange(flody)
- POJ1860(Currency Exchange)(Bellman-Ford)
- POJ1860-Currency Exchange(bellman-ford求正环)
- POJ1860:Currency Exchange
- poj1860 - Currency Exchange
- Currency Exchange poj1860
- poj1860--Currency Exchange
- poj1860 Currency Exchange
- poj1860--Currency Exchange
- POJ1860 Currency Exchange
- POJ1860 Currency Exchange
- poj1860--Currency Exchange
- POJ1860-Currency Exchange
- POJ1860 - Currency Exchange
- POJ1860---Currency Exchange
- poj1860 Currency Exchange (bellman_ford)
- poj1860 - Currency Exchange
- 【POJ1860】Currency Exchange
- CodeForces 698A—Vacations(贪心)
- char & unsigned char & signed char
- MATLAB中如何将离散加速度积分求得速度
- hdu4395(01背包)
- 51nod 1120 机器人走方格v3
- poj1860 Currency Exchange(flody)
- Git用户手册--Git 工具
- C++基础:输入输出的格式控制
- hibernate类之间继承关系映射
- AFNetworking提示Invalid parameter not satisfying: URLString
- Swift 2.3 【Swift 和 Javascript 如何相互调用】
- UVA - 1149 Bin Packing
- 20160723
- WIN10无法连接VPN解决方案