51nod 1366 贫富差距(flody)
2017-12-14 20:20
253 查看
http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1366
题意:
思路:
如果不是一个连通块的话,肯定是无穷大的。
用floyd求出两两之间的最短路,然后在这些最短路中选最长的*d即可。
题意:
思路:
如果不是一个连通块的话,肯定是无穷大的。
用floyd求出两两之间的最短路,然后在这些最短路中选最长的*d即可。
#include<iostream> #include<cstdio> #include<cstring> #include<queue> using namespace std; const int inf = 0x3f3f3f3f; int n,k; int d[55][55]; char mp[55][55]; int main() { //freopen("in.txt","r",stdin); int T; scanf("%d",&T); while(T--) { memset(d,0x3f,sizeof(d)); scanf("%d%d",&n,&k); for(int i=1;i<=n;i++) { scanf("%s",mp[i]+1); for(int j=1;j<=n;j++) { if(mp[i][j]=='Y') d[i][j] = 1; } } for(int k=1;k<=n;k++) { for(int i=1;i<=n;i++) { for(int j=1;j<=n;j++) { d[i][j] = min(d[i][j],d[i][k]+d[k][j]); } } } int ans = 0; bool flag = true; for(int i=1;i<=n;i++) { if(!flag) break; for(int j=i+1;j<=n;j++) { if(d[i][j]==inf) {flag=false;break;} ans = max(ans,d[i][j]); } } if(flag) printf("%d\n",ans*k); else puts("-1"); } return 0; }
相关文章推荐
- 51nod 1366 贫富差距 弗洛伊德
- 51nod 1366 贫富差距(最短路)
- 51Nod 1366 贫富差距
- 51nod 1366 贫富差距
- 51Nod-1366-贫富差距
- 51nod 1366 贫富差距【并查集+Floyd】
- 51nod 1366 贫富差距 (并查集+最短路径)
- 51nod-1366:贫富差距
- 51nod 1366 贫富差距
- 51Nod-1366 贫富差距
- 1366 贫富差距
- 51Nod - 1366
- 51nod oj 1366 贫富差距【枚举+最长的短路】
- 51nod 1015 水仙花数
- 51Nod(1086)
- [dp专题-四边形不等式优化]51nod 1022
- 51nod 1424 零树(树形dp)
- 51NOD——1117 聪明的木匠(可用优先队列解决的贪心算法)
- 51nod 1640 天气晴朗的魔法 克鲁斯卡尔
- 51nod 1101换零钱(背包)