[USACO09JAN]最好的地方Best Spot
OJ题号:洛谷2935
思路:Floyd
#pragma GCC optimize ("O3")
#include<cstdio>
#include<cctype>
#define inf 0x7fffffff>>1
inline int min(const int a,const int b) {
return a<b?a:b;
}
inline int getint() {
int ch;
while(!isdigit(ch=getchar()));
int x=ch^'';
while(isdigit(ch=getchar())) x=((x+(x<<))<<)+(ch^'');
return x;
}
int main() {
int p=getint(),F=getint(),C=getint();
int f[F];
for(int i=;i<F;i++) {
f[i]=getint();
}
int c[p+][p+];
for(int i=;i<=p;i++) {
for(int j=;j<=p;j++) {
c[i][j]=(i==j)?:inf;
}
}
for(int i=;i<C;i++) {
int a=getint(),b=getint(),t=getint();
c[b][a]=c[a][b]=t;
}
for(int k=;k<=p;k++) {
for(int i=;i<=p;i++) {
for(int j=;j<=p;j++) {
c[i][j]=min(c[i][j],c[i][k]+c[k][j]);
}
}
}
int ans,mmin=inf;
for(int i=;i<=p;i++) {
int tmp=;
for(int j=;j<F;j++) {
tmp+=c[i][f[j]];
}
if(tmp<mmin) {
ans=i;
mmin=tmp;
}
}
printf("%d\n",ans);
return ;
}
[USACO09JAN]最好的地方Best Spot的更多相关文章
- 洛谷——P2935 [USACO09JAN]最好的地方Best Spot
P2935 [USACO09JAN]最好的地方Best Spot 题目描述 Bessie, always wishing to optimize her life, has realized that ...
- $P2935 [USACO09JAN]最好的地方Best Spot$
P2935 [USACO09JAN]最好的地方Best Spot Floyd的水题(黄题) 海星. 这可能是我第一道发的Floyd的博客 inline void Floyd(){ ;k<=n;k ...
- 洛谷 P2935 [USACO09JAN]最好的地方Best Spot
题目描述 Bessie, always wishing to optimize her life, has realized that she really enjoys visiting F (1 ...
- Luogu P2935 最好的地方Best Spot
Luogu P2935 最好的地方Best Spot 这道题就是一道近乎裸的Floyd,因为数据很小,所以用领接表存图就可以了. #include<bits/stdc++.h> #defi ...
- URAL 1934 Black Spot(最短路)
Black Spot Time limit: 1.0 secondMemory limit: 64 MB Bootstrap: Jones's terrible leviathan will find ...
- spot 5、ALOS监督分类波段组成
spot 5监督分类RGB:412 ALOS分类波段RGB:432
- Spot light工具集
Spot light on UNIX 安装没什么问题 Spot light on Oracle 必须安装32位的客户端,不然搞死你 两者的界面都是吊炸天啊
- BZOJ3394: [Usaco2009 Jan]Best Spot 最佳牧场
3394: [Usaco2009 Jan]Best Spot 最佳牧场 Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 11 Solved: 9[Sub ...
- UVA 141 The Spot Game 斑点游戏。。
The Spot Game The game of Spot is played on an NxN board as shown below for N = 4. During the game ...
随机推荐
- 如何录制Chrome或者Linux下的应用
说明: PortMapping的这种用法其实早就有了,开始我一直没注意到这点,后面才发现了这个功能,特别在<性能测试进阶指南Loadrunner11实战>第二版中更新. 不是所有的对象都能 ...
- https请求抛出异常
ServicePointManager.SecurityProtocol = (SecurityProtocolType)3072;// SecurityProtocolType.Tls1.2;
- java & python猜数字游戏对比
1.java版 package day03; import java.util.Random;import java.util.Scanner; /** * 猜数字游戏 * 随机生成一个1-100之间 ...
- python functools
# 工具函数import functools print(dir(functools)) # partial函数(偏函数)def showarg(*args,**kw): print(args) pr ...
- yarn的安装与使用及与npm对应的命令
在Nodejs环境下,通过npm install -g yarn 命令进行全局安装 例如:yarn versionyarn inityarn installyarn add vueyarn add v ...
- POJ 2243 简单搜索 (DFS BFS A*)
题目大意:国际象棋给你一个起点和一个终点,按骑士的走法,从起点到终点的最少移动多少次. 求最少明显用bfs,下面给出三种搜索算法程序: // BFS #include<cstdio> #i ...
- Nodejs通过账号密码连接MongoDB数据库
转自https://blog.csdn.net/szu_lzz/article/details/77435804#commentBox 1.创建管理员 首先开启Mongo服务,然后切换admin数据库 ...
- luogu1355 神秘大三角
题解: 计算几何入门题 按逆时针方向访问三角形的边 然后作叉积判断点是否在边的顺时针方向 叉积和点积都有分配率 但不满足结合律 代码: #include <bits/stdc++.h> u ...
- 构建ASP.NET MVC5+EF6+EasyUI 1.4.3+Unity4.x注入的后台管理系统(66)-MVC WebApi 用户验证 (2)
前言: 构建ASP.NET MVC5+EF6+EasyUI 1.4.3+Unity4.x注入的后台管理系统(65)-MVC WebApi 用户验证 (1) 回顾上一节,我们利用webapi简单的登录并 ...
- docker 安装配置
1. 安装docker 环境是ubuntu 14.04 参照: https://help.aliyun.com/document_detail/60742.html # step 1: 安装必要的一 ...