UVa 11015 - 05-2 Rendezvous
題目:有一個班級的學生要一起寫作業,所以他們要到一個統一的地點。現在給你他們各自的位置,
問集合地點定在哪,能够讓全部人走的總路徑長度最小。
分析:圖論、最短路。直接利用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的更多相关文章
- UVA 10194 (13.08.05)
:W Problem A: Football (aka Soccer) The Problem Football the most popular sport in the world (ameri ...
- UVA 400 (13.08.05)
Unix ls The computer company you work for is introducing a brand new computer line and is developi ...
- UVA 1456 六 Cellular Network
Cellular Network Time Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld & %llu Submit S ...
- UVA 11054 Wine trading in Gergovia 葡萄酒交易 贪心+模拟
题意:一题街道上很多酒店,交易葡萄酒,正数为卖出葡萄酒,负数为需要葡萄酒,总需求量和总售出量是相等的,从一家店到另外一家店需要路费(路费=距离×运算量),假设每家店线性排列且相邻两店之间距离都是1,求 ...
- UVA 11768 - Lattice Point or Not(数论)
UVA 11768 - Lattice Point or Not option=com_onlinejudge&Itemid=8&page=show_problem&categ ...
- UVa 10305 Ordering Tasks (例题 6-15)
传送门: https://uva.onlinejudge.org/external/103/10305.pdf 拓扑排序(topological sort)简单题 自己代码的思路来自: ==> ...
- UVA 10534 Wavio Sequence
题目链接:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=17&p ...
- UVA 1412 Fund Management (预处理+状压dp)
状压dp,每个状态可以表示为一个n元组,且上限为8,可以用一个九进制来表示状态.但是这样做用数组开不下,用map离散会T. 而实际上很多九进制数很多都是用不上的.因此类似uva 1601 Mornin ...
- 树形DP UVA 1292 Strategic game
题目传送门 /* 题解:选择一个点,它相邻的点都当做被选择,问最少选择多少点将所有点都被选择 树形DP:dp[i][0/1]表示当前点选或不选,如果选,相邻的点可选可不选,取最小值 */ /***** ...
随机推荐
- legend---七、jquery如何选中select的selected的选择上的自定义属性
legend---七.jquery如何选中select的selected的选择上的自定义属性 一.总结 一句话总结:用冒号属性选择器 var type=$(this).children('option ...
- POJ 2436 二进制枚举
题意: 思路: 拆成二进制枚举 有哪个病毒在 判一判 就好了 //By SiriusRen #include <cstdio> #include <cstring> #incl ...
- Gym - 100637A Nano alarm-clocks 模拟
题意:有n个时钟,只能顺时针拨,问使所有时间相同的最小代价是多少 思路:将时间排序,枚举拨动到每一个点的时间就好了,容易证明最终时间一定是其中之一 #include <iostream> ...
- Python(六) Python 函数
一.认识函数 help(方法名字) help(round) 1.功能性 2.隐藏细节 3.避免编写重复的代码 4.组织代码 自定义函数 二.函数的定义及运行特点 # 递归 def sum_num(n ...
- 紫书 例题 9-12 UVa 12186 (树形dp)
这道题还是比较简单的,对于当前节点,算出每个儿子需要的人数 然后再算出当前节点需要多少个人数,然后排个序加上去就好了. #include<cstdio> #include<vecto ...
- LRJ入门经典-0903切蛋糕305
原题 LRJ入门经典-0903切蛋糕305 难度级别:B: 运行时间限制:1000ms: 运行空间限制:256000KB: 代码长度限制:2000000B 试题描述 如图所示有一个矩形蛋糕,上面划分成 ...
- 【Uva 1626】Brackets sequence
[Link]: [Description] 括号序列由这样的规则生成: 1.空字符是一个括号序列; 2.在括号序列两端加上一对括号也是括号序列; 如(s),[s]; 3.两个括号序列A和B,连在一起, ...
- Mysql学习总结(8)——MySql基本查询、连接查询、子查询、正则表达查询讲解
查询数据指从数据库中获取所需要的数据.查询数据是数据库操作中最常用,也是最重要的操作.用户可以根据自己对数据的需求,使用不同的查询方式.通过不同的查询方式,可以获得不同的数据.MySQL中是使用SEL ...
- Mysql学习总结(7)——MySql索引原理与使用大全
一.索引介绍 索引是对数据库表中一列或多列的值进行排序的一种结构.在关系数据库中,索引是一种与表有关的数据库结构,它可以使对应于表的SQL语句执行得更快.索引的作用相当于图书的目录,可以根据目录中的页 ...
- Apache Thrift使用总结
使用感受 之前对Thrift的理解有点不准确,使用之后发现Thrift比想象中的要简单得多. Thrift做的事情就是跨语言的分布式RPC,通过编写.thrift文件声明接口类和方法,client调用 ...