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

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

分析:圖論、最短路。直接利用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. poj--3281-- DiningI(最大流)

    Dining Time Limit: 2000MS   Memory Limit: 65536KB   64bit IO Format: %I64d & %I64u Submit Status ...

  2. js 判断浏览器是否滚动到底部

    //jquery 实现代码 $(document).height() == $(window).height() + $(window).scrollTop() 1 整个空间的高度 包含(滚动条距离顶 ...

  3. 基于CANopen DSP402的运动控制笔记

    常用的mode of operation 有以下几种: 控制字 control word: 6--------------7---------------15--------------------7 ...

  4. Linux常用下载软件

    1.TransmissionTransmission是一个BitTorrent客户端软件,Ubunut默认自带的下载软件,它支持速度限制.制作种子.远程控制.磁力链接.数据加密.损坏修复.数据来源交换 ...

  5. mysql分页小结

    mysql.select('*').from('books') .join('cSessionInfo', 'books.openid', 'cSessionInfo.open_id') .limit ...

  6. ES6学习笔记(十)代理器Proxy

    Java可以使用面向切面(AOP)的方法来实现某些统一的操作,比如某个操作的前置通知,后置通知等等,这种操作非常方便,其本质便是动态代理,JS的代理Proxy代理该如何使用呢? 某位大神的实现如下: ...

  7. iOS Scheme 跳转主流实现方案

    iOS Scheme跳转主流实现方案主要是路由跳转,目前iOS常用路由框架是JLRouter.HHRouter.MGJRouter. 但是这些路由库都各有不足,首先是JLRouter,用不到的功能繁多 ...

  8. class-dump 和 iOSOpenDev 的使用

    class-dump 官网地址:这里 我这里下载的是 class-dump-3.5.dmg 版本号的. 双击.dmg 文件,将  拉倒 /usr / local / bin 文件夹下,这样就能够在终端 ...

  9. PipeCAD之管道标准库PipeStd

    PipeCAD之管道标准库PipeStd eryar@163.com Key Words. PipeCAD, PipeStd, 管道设计软件,管件库 1. Introduction 前不久,两位老友徐 ...

  10. Android Gson解析json工具类封装

    package com.springSecurity.gson; import java.util.ArrayList; import java.util.List; import java.util ...