Luogu P2935 最好的地方Best Spot

这道题就是一道近乎裸的Floyd,因为数据很小,所以用领接表存图就可以了。

#include<bits/stdc++.h>
#define INF 0x3fffffff
#define N 510 using namespace std; int p,f,c,mmin=INF,sum,ans;
int like[N],e[N][N]; void Read() {
scanf("%d%d%d",&p,&f,&c);
for(int i=1;i<=p;i++) {
for(int j=1;j<=p;j++) {
e[i][j]=INF;
}
e[i][i]=0;
}
for(int i=1;i<=f;i++) {
scanf("%d",&like[i]);
}
for(int i=1;i<=c;i++) {
int a,b,t;
scanf("%d%d%d",&a,&b,&t);
e[a][b]=t;
e[b][a]=t;
}
return;
} void Floyd() {
for(int k=1;k<=p;k++) {
for(int i=1;i<=p;i++) {
for(int j=1;j<=p;j++) {
e[i][j]=min(e[i][j],e[i][k]+e[k][j]);
}
}
}
return;
} void Print() {
for(int i=1;i<=p;i++) {
sum=0;
for(int j=1;j<=f;j++) {
sum+=e[i][like[j]];
}
if(sum<mmin) {
mmin=sum;
ans=i;
}
}
printf("%d",ans);
return;
} int main()
{
Read();
Floyd();
Print();
return 0;
}

Luogu P2935 最好的地方Best Spot的更多相关文章

  1. 洛谷——P2935 [USACO09JAN]最好的地方Best Spot

    P2935 [USACO09JAN]最好的地方Best Spot 题目描述 Bessie, always wishing to optimize her life, has realized that ...

  2. $P2935 [USACO09JAN]最好的地方Best Spot$

    P2935 [USACO09JAN]最好的地方Best Spot Floyd的水题(黄题) 海星. 这可能是我第一道发的Floyd的博客 inline void Floyd(){ ;k<=n;k ...

  3. 洛谷 P2935 [USACO09JAN]最好的地方Best Spot

    题目描述 Bessie, always wishing to optimize her life, has realized that she really enjoys visiting F (1 ...

  4. [USACO09JAN]最好的地方Best Spot

    OJ题号:洛谷2935 思路:Floyd #pragma GCC optimize ("O3") #include<cstdio> #include<cctype ...

  5. Luogu 魔法学院杯-第二弹(萌新的第一法blog)

    虽然有点久远  还是放一下吧. 传送门:https://www.luogu.org/contest/show?tid=754 第一题  沉迷游戏,伤感情 #include <queue> ...

  6. luogu p1268 树的重量——构造,真正考验编程能力

    题目链接:http://www.luogu.org/problem/show?pid=1268#sub -------- 这道题费了我不少心思= =其实思路和标称毫无差别,但是由于不习惯ACM风格的题 ...

  7. URAL 1934 Black Spot(最短路)

    Black Spot Time limit: 1.0 secondMemory limit: 64 MB Bootstrap: Jones's terrible leviathan will find ...

  8. [luogu P2170] 选学霸(并查集+dp)

    题目传送门:https://www.luogu.org/problem/show?pid=2170 题目描述 老师想从N名学生中选M人当学霸,但有K对人实力相当,如果实力相当的人中,一部分被选上,另一 ...

  9. [luogu P2647] 最大收益(贪心+dp)

    题目传送门:https://www.luogu.org/problem/show?pid=2647 题目描述 现在你面前有n个物品,编号分别为1,2,3,--,n.你可以在这当中任意选择任意多个物品. ...

随机推荐

  1. 【Leetcode_easy】1154. Day of the Year

    problem 1154. Day of the Year solution class Solution { public: int dayOfYear(string date) { // 平年 闰 ...

  2. 【Leetcode_easy】997. Find the Town Judge

    problem 997. Find the Town Judge solution: class Solution { public: int findJudge(int N, vector<v ...

  3. ELK之7版本Elastic Maps功能介绍

    Elasticsearch 7.0 中还引入了一个新的聚合来处理地理地图图块,允许用户在地图上放大和缩小,而不会改变结果数据的形状,实现更加平滑地缩放 Elastic Maps:使用纳秒精度存储时序数 ...

  4. svn服务器端—管理员分配权限

    1.SVN服务器搭建和使用 下载地址:http://subversion.apache.org/packages.html 滚动到浏览器底部,下载并安装:VisualSVN服务器端和tortoiseS ...

  5. InnoDB一定会在索引中加上主键吗?

    先回答问题,是的. 故事, 如下图,今天查看慢sql发现同事在建索引的时候竟然包含了主键,第一感觉这种姿势不对. 我记得很多文章都说过二级索引会自动带上主键,为什么还有人这么操作,后来差了些资料,如下 ...

  6. win10改装win7

    参考链接: https://jingyan.baidu.com/article/3ea51489d0f3c852e61bba01.html 1. 制作win7 U盘启动盘 2. 设置BIOS 1:OS ...

  7. 1.IO的演进

      1.Java IO 演进之路 本文围绕着一下几个问题 1.Java 中 BIO.NIO.AIO 之间的区别及应用场景. 2.阻塞(Block)与非阻塞(Non-Block)区别. 3.同步(Syn ...

  8. php创建生成数组的相关函数

    php中和数组创建生成的函数有很多,用于定义数组的函数array(),数组合并函数array_combine(),还有array_fill(),array_fill_keys(),range()等等. ...

  9. python技巧 — Chrome浏览器中的 XPath Helper

    用于XPath 爬取网页结构的时候使用, 安装后 快捷键调用 左边 ctrl+ shift+x 启动 安装流程: 1. 打开chrome浏览器,扩展程序 .搜索 XPath Helper 下载安装(前 ...

  10. FFmpeg中AVFrame.linesize的含义

    在第一节FFmpeg开发教程一.FFmpeg 版 Hello world中遇到一个问题,在保存YUV的时候,粗暴的使用: fwrite(buf, 1, xsize * ysize, f); 方式去拷贝 ...