题目链接

题目

题目描述

Farmer John's farm has an outdated network of M pipes (1 <= M <= 500) for pumping milk from the barn to his milk storage tank. He wants to remove and update most of these over the next year, but he wants to leave exactly one path worth of pipes intact, so that he can still pump milk from the barn to the storage tank.

The pipe network is described by N junction points (1 <= N <= 500), each of which can serve as the endpoint of a set of pipes. Junction point 1 is the barn, and junction point N is the storage tank. Each of the M bi-directional pipes runs between a pair of junction points, and has an associated latency (the amount of time it takes milk to reach one end of the pipe from the other) and capacity (the amount of milk per unit time that can be pumped through the pipe in steady state). Multiple pipes can connect between the same pair of junction points.

For a path of pipes connecting from the barn to the tank, the latency of the path is the sum of the latencies of the pipes along the path, and the capacity of the path is the minimum of the capacities of the pipes along the path (since this is the "bottleneck" constraining the overall rate at which milk can be pumped through the path). If FJ wants to send a total of X units of milk through a path of pipes with latency L and capacity C, the time this takes is therefore L + X/C.

Given the structure of FJ's pipe network, please help him select a single path from the barn to the storage tank that will allow him to pump X units of milk in a minimum amount of total time.

输入描述

  • Line 1: Three space-separated integers: N M X (1 <= X <= 1,000,000).

  • Lines 2..1+M: Each line describes a pipe using 4 integers: I J L C.

    I and J (1 <= I,J <= N) are the junction points at both ends

    of the pipe. L and C (1 <= L,C <= 1,000,000) give the latency

    and capacity of the pipe.

输出描述

  • Line 1: The minimum amount of time it will take FJ to send milk

    along a single path, rounded down to the nearest integer.

示例1

输入

3 3 15
1 2 10 3
3 2 10 2
1 3 14 1

输出

27

说明

INPUT DETAILS:

FJ wants to send 15 units of milk through his pipe network. Pipe #1

connects junction point 1 (the barn) to junction point 2, and has a latency

of 10 and a capacity of 3. Pipes #2 and #3 are similarly defined.

OUTPUT DETAILS:

The path 1->3 takes 14 + 15/1 = 29 units of time. The path 1->2->3 takes

20 + 15/2 = 27.5 units of time, and is therefore optimal.

题解

知识点:枚举,最短路。

每个管道有两个参数,延迟 \(L\) 和能力 \(C\) ,一条路径的时间花费是 \(\sum L_i + \frac{X}{\min(C_i)}\) ,显然路径上所有管道的 \(C\) 要尽可能大而 \(L\) 要尽可能小。然而,单看 \(L\) 尽可能小,最短路就能解决,但是另一个参数 \(C\) 就不确定了,而且没有办法兼顾两个参数。因此,我们要想办法确定一个参数。

我们已经知道 \(L\) 很好跑最短路,而 \(C\) 没有什么好的办法,那么我们手动控制 \(C\) 。枚举 \(C\) 的大小,每次固定一个 \(C\) 控制跑最短路时选取的管道,小于 \(C\) 的不选,最终取时间最小值即可。

当然也可以二分 \(C\) 不过这里枚举就能过了。

时间复杂度 \(O(\max(C_i)(n+m)\log m)\)

空间复杂度 \(O(n+m)\)

代码

#include <bits/stdc++.h>
#define ll long long using namespace std; template<class T>
struct Graph {
struct edge {
int v, nxt;
T w;
};
int idx;
vector<int> h;
vector<edge> e; Graph(int n, int m) :idx(0), h(n + 1), e(m + 1) {}
void init(int n) {
idx = 0;
h.assign(n + 1, 0);
} void add(int u, int v, T w) {
e[++idx] = edge{ v,h[u],w };
h[u] = idx;
}
}; const int N = 507, M = 507 << 1;
Graph<pair<int, int>> g(N, M);
int n, m, x; int dis[N];
bool vis[N];
struct node {
int v, w;
friend bool operator<(const node &a, const node &b) {
return a.w > b.w;
}
};
priority_queue<node> pq;
void dijkstra(int st, int val) {
for (int i = 1;i <= n;i++) dis[i] = 0x3f3f3f3f, vis[i] = 0;
dis[st] = 0;
pq.push({ st,0 });
while (!pq.empty()) {
int u = pq.top().v;
pq.pop();
if (vis[u]) continue;
vis[u] = 1;
for (int i = g.h[u];i;i = g.e[i].nxt) {
int v = g.e[i].v;
auto [l, c] = g.e[i].w;
if (c < val) continue;
if (dis[v] > dis[u] + l) {
dis[v] = dis[u] + l;
pq.push({ v,dis[v] });
}
}
}
} int main() {
std::ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
cin >> n >> m >> x;
int mx = 0;
for (int i = 1;i <= m;i++) {
int u, v, l, c;
cin >> u >> v >> l >> c;
g.add(u, v, { l,c });
g.add(v, u, { l,c });
mx = max(mx, c);
}
int ans = 0x3f3f3f3f;
for (int i = mx;i >= 1;i--) {
dijkstra(1, i);
ans = min(ans, (int)round(dis[n] + x / i));
}
cout << ans << '\n';
return 0;
}

NC24370 [USACO 2012 Dec S]Milk Routing的更多相关文章

  1. 【BZOJ】【1717】【USACO 2006 Dec】Milk Patterns产奶的模式

    后缀数组 o(︶︿︶)o 唉傻逼了一下,忘了把后缀数组的字典范围改回20001,直接21交了上去,白白RE了两发……sigh 既然要找出现了K次的子串嘛,那当然要用后缀数组了>_>(因为我 ...

  2. USACO Milk Routing

    洛谷 P3063 [USACO12DEC]牛奶的路由Milk Routing 洛谷传送门 JDOJ 2334: USACO 2012 Dec Silver 3.Milk Routing JDOJ传送门 ...

  3. USACO翻译:USACO 2013 DEC Silver三题

    USACO 2013 DEC SILVER 一.题目概览 中文题目名称 挤奶调度 农场航线 贝西洗牌 英文题目名称 msched vacation shuffle 可执行文件名 msched vaca ...

  4. USACO翻译:USACO 2014 DEC Silver三题

    USACO 2014 DEC SILVER 一.题目概览 中文题目名称 回程 马拉松 奶牛慢跑 英文题目名称 piggyback marathon cowjog 可执行文件名 piggyback ma ...

  5. USACO翻译:USACO 2012 FEB Silver三题

    USACO 2012 FEB SILVER 一.题目概览 中文题目名称 矩形草地 奶牛IDs 搬家 英文题目名称 planting cowids relocate 可执行文件名 planting co ...

  6. USACO翻译:USACO 2012 JAN三题(2)

    USACO 2012 JAN(题目二) 一.题目概览 中文题目名称 叠干草 分干草 奶牛联盟 英文题目名称 stacking baleshare cowrun 可执行文件名 stacking bale ...

  7. USACO翻译:USACO 2012 JAN三题(1)

    USACO 2012 JAN(题目一) 一.题目概览 中文题目名称 礼物 配送路线 游戏组合技 英文题目名称 gifts delivery combos 可执行文件名 gifts delivery c ...

  8. 【USACO 2012 Open】Running Laps(树状数组)

    53 奶牛赛跑 约翰有 N 头奶牛,他为这些奶牛准备了一个周长为 C 的环形跑牛场.所有奶牛从起点同时起跑,奶牛在比赛中总是以匀速前进的,第 i 头牛的速度为 Vi.只要有一头奶牛跑完 L 圈之后,比 ...

  9. [USACO 2017 Dec Gold] Tutorial

    Link: USACO 2017 Dec Gold 传送门 A: 为了保证复杂度明显是从终结点往回退 结果一开始全在想优化建边$dfs$……其实可以不用建边直接$multiset$找可行边跑$bfs$ ...

  10. 洛谷 P3063 [USACO12DEC]牛奶的路由Milk Routing

    P3063 [USACO12DEC]牛奶的路由Milk Routing 题目背景 征求翻译.如果你能提供翻译或者题意简述,请直接发讨论,感谢你的贡献. 题目描述 Farmer John's farm ...

随机推荐

  1. Nginx Location 深入剖析及动静分离简易配置

    本文为博主原创,未经允许不得转载: 1. location 使用分析 location 是 Nginx 配置 中的一个指令,用于访问的 URL 匹配,而在这个 location 中所配置的每个指令将会 ...

  2. 基于java+springboot的商城网站、电子商城管理系统

    该系统是基于java+springboot+vue开发的在线商城网站.是给师弟开发的课程作业.学习过程中,遇到问题可以咨询作者. 演示地址 前台地址: http://shop.gitapp.cn 后台 ...

  3. 8. exporter

    一.已经实现的收集器 1.1 可收集的内存指标 1.2 可收集的jetty指标 二.自定义收集 2.1 summer 2.2 histogram 三.架构设计 exporter作为Prometheus ...

  4. MCU芯片设计流程

    MCU设计流程 1.产品开发整体流程 Integrated Product Development(IPD) TR-Technique Review-技术评审 xDCP-管理层决定是否开发 这里的验证 ...

  5. 【TouchGFX】屏幕概念

    Screen构成 界面布局 View, 逻辑处理 Presenter Currently Active Screen 因TouchGFX分配内存的的方式是,按照最大的Screen分配,即最大View+ ...

  6. STM32 芯片锁死解决方法

    芯片锁死原因: 1.烧进去的工程对应器件与目标器件不一致: 2.烧进去的工程HSE_VALUE与目标板上晶振频率不一致: 3.... 解决方法: 1.工程设置 2.按住复位按键,或短接复位脚电容,点击 ...

  7. [转帖]理解 Linux backlog/somaxconn 内核参数

    引言 在研究IOTDB的时候,启动服务的时候会有个报警. WARN: the value of net.core.somaxconn (=4096) is too small, please set ...

  8. [转帖]《Linux性能优化实战》笔记(二)—— CPU 上下文切换(上)

    上一篇的最后一个例子,在多个进程竞争CPU时,我们看到每个进程实际上%usr部分只有20%多,70%多是在wait,但是load远远高于单个进程使用CPU达到100%. 这让我想到之前看的RWP公开课 ...

  9. 是否开启raid卡缓存的影响

    开启raid卡缓存 Write back 对IO性能的影响 背景 公司买了一台服务器. 想进行一下升级 但是因为管理员担心数据丢失, 使用了write through + (raid6 + hotsp ...

  10. 《SAIS Supervising and Augmenting Intermediate Steps for Document-Level Relation Extraction》论文阅读笔记

    代码   原文地址   预备知识: 1.什么是标记索引(token indices)? 标记索引是一种用于表示文本中的单词或符号的数字编码.它们可以帮助计算机理解和处理自然语言.例如,假如有一个字典{ ...