AOJ 0189 Convenient Location (Floyd)
来源:互联网 发布:网宿科技 知乎 编辑:程序博客网 时间:2024/05/08 05:35
题意:
求某一个办公室 到其他所有办公室的 总距离最短 办公室数 不超过10
输入:
多组输入,每组第一行为n (1 ≤ n ≤ 45),接下来n行是 (x, y, d),x到y的距离是d
输出:
办公室号 和 最短距离
Floyd水题 - -
AC代码如下:
//// AOJ 0189 Convenient Location//// Created by TaoSama on 2015-03-20// Copyright (c) 2015 TaoSama. All rights reserved.//#include <algorithm>#include <cctype>#include <cmath>#include <cstdio>#include <cstdlib>#include <cstring>#include <iomanip>#include <iostream>#include <map>#include <queue>#include <string>#include <set>#include <vector>#define CLR(x,y) memset(x, y, sizeof(x))using namespace std;const int INF = 0x3f3f3f3f;const int MOD = 1e9 + 7;const int N = 1e5 + 10;int n, dp[15][15];int main() {#ifdef LOCALfreopen("in.txt", "r", stdin);//freopen("out.txt","w",stdout);#endifios_base::sync_with_stdio(0);while(cin >> n && n) {int V = 0;memset(dp, 0x3f, sizeof dp);for(int i = 1; i <= n; ++i) {int x, y, v; cin >> x >> y >> v;dp[x][y] = dp[y][x] = v;V = max(V, max(x, y));}for(int k = 0; k <= V; ++k)for(int i = 0; i <= V; ++i)for(int j = 0; j <= V; ++j)dp[i][j] = min(dp[i][j], dp[i][k] + dp[k][j]);int ans = INF, loc;for(int i = 0; i <= V; ++i) {int t = 0;for(int j = 0; j <= V; ++j) {if(i == j) continue;t += dp[i][j];}if(t < ans) ans = t, loc = i;}cout << loc << ' ' << ans << endl;}return 0;}
0 0
- AOJ 0189 Convenient Location (Floyd)
- AOJ 0189 Convenient Location(最短路)
- AOJ-0189-Convenient Location 最短路【floyd算法】
- Aizu - 0189 Convenient Location(floyd)
- Aizu 0189 Convenient Location【floyd】
- Aizu - 0189 Convenient Location(floyd)
- Aizu 0189 Convenient Location 【全局最短路 floyd】
- Aizu 0189 Convenient Location
- Aizu 0189 Convenient Location
- aoj0189 Convenient Location floyd-warshall最短路
- AOJ 2200 Mr. Rito Post Office (Floyd预处理、dp)
- 【aoj 】 幂集(回溯)
- AOJ
- Aoj
- Aizu 0189 (Floyd)
- AOJ GRL_1_C: All Pairs Shortest Path (Floyd-Warshall算法求任意两点间的最短路径)(Bellman-Ford算法判断负圈)
- AOJ 0033 Ball (dfs)
- AOJ 0558 Cheese (bfs)
- Linux mysql: ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO) 的解决办
- 第三周项目3:程序的多文件组织
- 常用的vim命令,主要是写给宝贝儿方便工作查看的
- Oracle Rman 命令详解(List report backup configure)
- HDOJ 2040 亲和数
- AOJ 0189 Convenient Location (Floyd)
- 大数据处理及其研究进展
- 华为 机试题 2011
- 蓝桥杯算法训练——2的次幂表示
- 浅谈Android中Http请求与缓存(上)
- C#中Socket通信编程的异步实现
- hdu 2489 Minimal Ratio Tree【深搜+最小生成树】
- UIImageView的contentMode属性详解
- Python2.2-原理之类型和运算