洛谷——P2935 [USACO09JAN]最好的地方Best Spot
P2935 [USACO09JAN]最好的地方Best Spot
题目描述
Bessie, always wishing to optimize her life, has realized that she really enjoys visiting F (1 <= F <= P) favorite pastures F_i of the P (1 <= P <= 500; 1 <= F_i <= P) total pastures (conveniently
numbered 1..P) that compose Farmer John's holdings.
Bessie knows that she can navigate the C (1 <= C <= 8,000) bidirectional cowpaths (conveniently numbered 1..C) that connect various pastures to travel to any pasture on the entire farm. Associated with each path P_i is a time T_i (1 <= T_i <= 892) to traverse that path (in either direction) and two path endpoints a_i and b_i (1 <= a_i <= P; 1 <= b_i <= P).
Bessie wants to find the number of the best pasture to sleep in so that when she awakes, the average time to travel to any of her F favorite pastures is minimized.
By way of example, consider a farm laid out as the map below shows, where *'d pasture numbers are favorites. The bracketed numbers are times to traverse the cowpaths.
1*--[4]--2--[2]--3
| |
[3] [4]
| |
4--[3]--5--[1]---6---[6]---7--[7]--8*
| | | |
[3] [2] [1] [3]
| | | |
13* 9--[3]--10*--[1]--11*--[3]--12*
The following table shows distances for potential 'best place' of pastures 4, 5, 6, 7, 9, 10, 11, and 12:
* * * * * * Favorites * * * * * *
Potential Pasture Pasture Pasture Pasture Pasture Pasture Average
Best Pasture 1 8 10 11 12 13 Distance
------------ -- -- -- -- -- -- -----------
4 7 16 5 6 9 3 46/6 = 7.67
5 10 13 2 3 6 6 40/6 = 6.67
6 11 12 1 2 5 7 38/6 = 6.33
7 16 7 4 3 6 12 48/6 = 8.00
9 12 14 3 4 7 8 48/6 = 8.00
10 12 11 0 1 4 8 36/6 = 6.00 ** BEST
11 13 10 1 0 3 9 36/6 = 6.00
12 16 13 4 3 0 12 48/6 = 8.00
Thus, presuming these choices were the best ones (a program would have to check all of them somehow), the best place to sleep is pasture 10.
约翰拥有P(1<=P<=500)个牧场.贝茜特别喜欢其中的F个.所有的牧场 由C(1 < C<=8000)条双向路连接,第i路连接着ai,bi,需要1(1<=Ti< 892)单 位时间来通过.
作为一只总想优化自己生活方式的奶牛,贝茜喜欢自己某一天醒来,到达所有那F个她喜欢的 牧场的平均需时最小.那她前一天应该睡在哪个牧场呢?请帮助贝茜找到这个最佳牧场.
此可见,牧场10到所有贝茜喜欢的牧场的平均距离最小,为最佳牧场.
输入输出格式
输入格式:
Line 1: Three space-separated integers: P, F, and C
Lines 2..F+1: Line i+2 contains a single integer: F_i
- Lines F+2..C+F+1: Line i+F+1 describes cowpath i with three
space-separated integers: a_i, b_i, and T_i
输出格式:
- Line 1: A single line with a single integer that is the best pasture in which to sleep. If more than one pasture is best, choose the smallest one.
输入输出样例
13 6 15 11 13 10 12 8 1 2 4 3 7 11 3 10 11 1 4 13 3 9 10 3 2 3 2 3 5 4 5 9 2 6 7 6 5 6 1 1 2 4 4 5 3 11 12 3 6 10 1 7 8 7
10
说明
As the problem statement
As the problem statement.
代码:
#include<cstdio> #include<cstdlib> #include<cstring> #include<iostream> #include<algorithm> #define N 501 #define maxn 999999 using namespace std; int n,m,t,x,y,z,s=maxn,ans,maxx,a[N],dis[N][N]; int read() { ,f=; char ch=getchar(); ; ch=getchar();} +ch-'; ch=getchar();} return x*f; } int main() { n=read(),t=read(),m=read(); ;i<=t;i++) a[i]=read(); ;i<=n;i++) ;j<=n;j++) dis[i][j]=(i!=j)*maxn; ;i<=m;i++) x=read(),y=read(),z=read(),dis[x][y]=z,dis[y][x]=z; ;k<=n;k++) ;i<=n;i++) ;j<=n;j++) if (dis[i][j]>dis[i][k]+dis[k][j]) dis[i][j]=dis[i][k]+dis[k][j]; ;i<=n;i++) { maxx=; ;j<=t;j++) maxx+=dis[i][a[j]]; if(s>maxx) s=maxx,ans=i; } printf("%d",ans); }
洛谷——P2935 [USACO09JAN]最好的地方Best Spot的更多相关文章
- 洛谷 P2935 [USACO09JAN]最好的地方Best Spot
题目描述 Bessie, always wishing to optimize her life, has realized that she really enjoys visiting F (1 ...
- $P2935 [USACO09JAN]最好的地方Best Spot$
P2935 [USACO09JAN]最好的地方Best Spot Floyd的水题(黄题) 海星. 这可能是我第一道发的Floyd的博客 inline void Floyd(){ ;k<=n;k ...
- [USACO09JAN]最好的地方Best Spot
OJ题号:洛谷2935 思路:Floyd #pragma GCC optimize ("O3") #include<cstdio> #include<cctype ...
- 2018.07.06 洛谷P2936 [USACO09JAN]全流Total Flow(最大流)
P2936 [USACO09JAN]全流Total Flow 题目描述 Farmer John always wants his cows to have enough water and thus ...
- 洛谷 P2932 [USACO09JAN]地震造成的破坏Earthquake Damage
P2932 [USACO09JAN]地震造成的破坏Earthquake Damage 题目描述 Wisconsin has had an earthquake that has struck Farm ...
- ●洛谷P2934 [USACO09JAN]安全出行Safe Travel
题链: https://www.luogu.org/problemnew/show/P2934 题解: 最短路(树),可并堆(左偏堆),并查集. 个人感觉很好的一个题. 由于题目已经明确说明:从1点到 ...
- 洛谷——P2936 [USACO09JAN]全流Total Flow
题目描述 Farmer John always wants his cows to have enough water and thus has made a map of the N (1 < ...
- 洛谷 P2936 [USACO09JAN]全流Total Flow
题目描述 Farmer John always wants his cows to have enough water and thus has made a map of the N (1 < ...
- 洛谷—— P2934 [USACO09JAN]安全出行Safe Travel || COGS ——279|| BZOJ——1576
https://www.luogu.org/problem/show?pid=2934 题目描述 Gremlins have infested the farm. These nasty, ugly ...
随机推荐
- [BZOJ3223/Tyvj1729]文艺平衡树
Description 您需要写一种数据结构(可参考题目标题),来维护一个有序数列 其中需要提供以下操作: 翻转一个区间,例如原有序序列是5 4 3 2 1,翻转区间是[2,4]的话,结果是5 2 3 ...
- 贪心 Codeforces Round #191 (Div. 2) A. Flipping Game
题目传送门 /* 贪心:暴力贪心水水 */ #include <cstdio> #include <algorithm> #include <cstring> us ...
- 287 Find the Duplicate Number 寻找重复数
一个长度为 n + 1 的整形数组,其中的数字都在 1 到 n 之间,包括 1 和 n ,可知至少有一个重复的数字存在.假设只有一个数字重复,找出这个重复的数字.注意: 不能更改数组内容(假设数 ...
- Java 8 (5) Stream 流 - 收集数据
在前面已经使用过collect终端操作了,主要是用来把Stream中的所有元素结合成一个List,在本章中,你会发现collect是一个归约操作,就像reduce一样可以接受各种做法作为参数,将流中的 ...
- jQuery学习笔记(4)-设置元素的属性和样式
一.前言 本篇主要讲解如何使用jQuery获取和操作元素的属性和css样式 二."DOM属性"与元素属性 1.运行一下代码 <img src="/images/lo ...
- 简单的css缩放动画,仿腾讯新闻的分享按钮和美团app底部的图标样式
最近看到一些好看的hover的图形缩放效果.然后自己就写了下,发现这2种效果都不错.如果伙伴们更好的实现方式可以在下面留言哦~ 还有美团的效果,我就不展示了,喜欢的可以去app应用上看看. 这两种效果 ...
- My-Eclipse 快捷键大全
Ctrl+1 快速修复(最经典的快捷键,就不用多说了) Ctrl+D: 删除当前行 Ctrl+Alt+↓ 复制当前行到下一行(复制增加) Ctrl+Alt+↑ 复制当前行到上一行(复制增加) Alt+ ...
- 三维重建:GitHub百度Apollo 2.0
GitHub:https://github.com/ApolloAuto/apollo 1. 关于Apollo的数据:Apollo的数据会如何开放? 自动驾驶数据将包括具有高分辨率图像和像素级别标注的 ...
- R语言学习 - 热图简化
绘制热图除了使用ggplot2,还可以有其它的包或函数,比如pheatmap::pheatmap (pheatmap包中的pheatmap函数).gplots::heatmap.2等. 相比于gg ...
- 【转载】tomcat部署web项目的3中方法
转载自:http://blog.csdn.net/wjx85840948/article/details/6749964/ 1.直接把项目复制到Tomcat安装目录的webapps目录中,这是最简单的 ...