題目:有一個班級的學生要一起寫作業,所以他們要到一個統一的地點。現在給你他們各自的位置,

問集合地點定在哪,能够讓全部人走的總路徑長度最小。

分析:圖論、最短路。直接利用Floyd計算最短路,找到和值最小的輸出就可以。

說明:又是太長時間沒刷題了。╮(╯▽╰)╭。

#include <algorithm>
#include <iostream>
#include <string>
#include <map> using namespace std; int dist[23][23]; int main()
{
int n, m, u, v, d, cases = 1;
string place;
while (cin >> n >> m && n+m) {
map<int, string>nameList;
for (int i = 0; i < n; ++ i) {
cin >> place;
nameList[i] = place;
} for (int i = 0; i < n; ++ i) {
for (int j = 0; j < n; ++ j)
dist[i][j] = 500000;
dist[i][i] = 0;
}
for (int i = 0; i < m; ++ i) {
cin >> u >> v >> d;
dist[u-1][v-1] = dist[v-1][u-1] = d;
} for (int k = 0; k < n; ++ k)
for (int i = 0; i < n; ++ i)
for (int j = 0; j < n; ++ j)
if (dist[i][j] > dist[i][k]+dist[k][j])
dist[i][j] = dist[i][k]+dist[k][j];
int space = 0, max = 500000;
for (int i = 0; i < n; ++ i) {
int sum = 0;
for (int j = 0; j < n; ++ j)
if (i != j)
sum += dist[i][j];
if (max > sum) {
max = sum;
space = i;
}
} cout << "Case #" << cases ++ << " : " << nameList[space] << endl;
}
return 0;
}

UVa 11015 - 05-2 Rendezvous的更多相关文章

  1. UVA 10194 (13.08.05)

    :W Problem A: Football (aka Soccer)  The Problem Football the most popular sport in the world (ameri ...

  2. UVA 400 (13.08.05)

     Unix ls  The computer company you work for is introducing a brand new computer line and is developi ...

  3. UVA 1456 六 Cellular Network

    Cellular Network Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu Submit S ...

  4. UVA 11054 Wine trading in Gergovia 葡萄酒交易 贪心+模拟

    题意:一题街道上很多酒店,交易葡萄酒,正数为卖出葡萄酒,负数为需要葡萄酒,总需求量和总售出量是相等的,从一家店到另外一家店需要路费(路费=距离×运算量),假设每家店线性排列且相邻两店之间距离都是1,求 ...

  5. UVA 11768 - Lattice Point or Not(数论)

    UVA 11768 - Lattice Point or Not option=com_onlinejudge&Itemid=8&page=show_problem&categ ...

  6. UVa 10305 Ordering Tasks (例题 6-15)

    传送门: https://uva.onlinejudge.org/external/103/10305.pdf 拓扑排序(topological sort)简单题 自己代码的思路来自: ==>  ...

  7. UVA 10534 Wavio Sequence

    题目链接:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=17&p ...

  8. UVA 1412 Fund Management (预处理+状压dp)

    状压dp,每个状态可以表示为一个n元组,且上限为8,可以用一个九进制来表示状态.但是这样做用数组开不下,用map离散会T. 而实际上很多九进制数很多都是用不上的.因此类似uva 1601 Mornin ...

  9. 树形DP UVA 1292 Strategic game

    题目传送门 /* 题解:选择一个点,它相邻的点都当做被选择,问最少选择多少点将所有点都被选择 树形DP:dp[i][0/1]表示当前点选或不选,如果选,相邻的点可选可不选,取最小值 */ /***** ...

随机推荐

  1. Gym - 100637B Lunch 规律

    题意:n个点,给定起点和终点,可以每次可以走一格或两格,走一格则需要一个代价,每个格子只能走一次,问从起点到终点并经过每一个点的最小代价 思路:这题我没看出什么道理,先打了个暴力,结果发现了个相当坑的 ...

  2. HTTP 各种特性应用(二)

    一.Cookie 通过 Set-Cookie 设置. 下次浏览器请求就会带上. 键值对,可以设置多个. Cookie 属性 max-age 和 expires 设置过期时间 Secure 只在 htt ...

  3. SQL函数-str()

    1 str()函数用于将数值类型数据转换未字符类型. 2 str()函数语法 select str(数字类型的表达式[,表达式总长度][,小数点后面的位数]) 表达式总长度和小数点后面的位数为可选择参 ...

  4. 威联通212P 在admin用户密码正确情况下仍然无法登录WEB页面解决办法

    *登录 telnet 执行以下语句: [~] # cp /etc/default_config/passwd /mnt/HDA_ROOT/.config/passwd[~] # cp /etc/def ...

  5. python 多线程探索

    前面已经了解过了,python多线程效率较低的主要原因是存在GIL,即Global Interpreter Lock(全局解释器锁).这里继续详细的看下GIL的说明与如何避免GIL的影响,从而提高py ...

  6. BZOJ3294: [Cqoi2011]放棋子(计数Dp,组合数学)

    题目链接 解题思路: 发现一个性质,如果考虑一个合法的方案可以将行和列都压到一起,也就是说,在占用行数和列数一定的情况下,行列互换是不会影响答案的,那么考虑使用如下方程: $f[i][j][k]$为占 ...

  7. PHP保留两位小数

    1.不四舍五入 $number = 23.43453;$english_format_number = number_format($number, 2, '.', '');echo $english ...

  8. vue踩坑- 报错npm ERR! cb() never called!

    在vue项目中引入饿了么elementUI组件的步骤之中,出现以下的错误: D:\my-project-first>npm i element-ui -S Unhandled rejection ...

  9. PatentTips - Device virtualization and assignment of interconnect devices

    BACKGROUND Standard computer interconnects, particularly for personal computers or workstations, may ...

  10. win10 WmiPrvSE.exe WMI Provider 占用CPU过高的问题

    重启 Windows Management Instrumentation 服务 重启 WMI service.   + ,输入: "services.msc" ,按 . 在 服务 ...