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

P3063 [USACO12DEC]牛奶的路由Milk Routing

题目背景

征求翻译。如果你能提供翻译或者题意简述,请直接发讨论,感谢你的贡献。

题目描述

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.

农民约翰的农场有一套老旧的管网,管网由M条管道(1<=M<=500)构成,用于将牛奶从谷仓运到储奶罐。 他想在明年移除和更新大部分管道,但他想原封不动地保留一条完整的路径,这样他仍然可以把牛奶从谷仓输送到储罐。

管网由N个节点(1<=N<=500)组成,每个点都可以作为一组管道的端点。结点1是谷仓,结点N是储罐。M条双向管道中的每一条都连接一对节点,并且都有一个延迟值(牛奶达到管的另一端的用时)和容量值(单位时间内可以稳定通过管道的牛奶量)。多条管道可以连接同一对节点。

对于一条连接谷仓与储罐的路径,路径的延迟等于沿途所有管道的延迟之和,路径的容量等于沿途管道最小的容量(因为这是制约牛奶运送的“瓶颈”)。如果约翰通过一条延迟为L、容量为C的管道运送X个单位的牛奶,需要的时间为L+X/C。

给出约翰的管网结构,请帮助他选择一条路径,使得他从谷仓到储罐运送X个单位牛奶的总时间最少。

输入输出格式

输入格式:

* 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.

第1行:三个空格分隔的整数:N M X(1<=X<=1000000)。

第2行到第M+1行:每一行描述一条管道,有4个整数:I J L C。I和J(1<=I,J<=N)是这条管道连接的两个点。L和C(1<=L,C<=1000000)是这条管道的延迟和容量。

输出格式:

* 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行:约翰沿着一条路径送牛奶花费的最少的时间,向下取整到最近的整数。

输入输出样例

输入样例#1: 复制

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

输出样例#1: 复制

27

说明

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.

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.

约翰想要通过管网运送15个单位的牛奶。管道1连接节点1(谷仓)和节点2,延迟为10,容量为3。管道2和管道3也以相似的方式来定义。

路径1->3花费14+15/1=29个单位的时间。路径1->2->3花费20+15/2=27.5个单位的时间,用时最少。

思路:最短路跑一下。

#include<queue>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define MAXN 5000
using namespace std;
int n,m,x,tot;
queue<int>que;
int vis[MAXN],dis[MAXN],num[MAXN];
int to[MAXN],cap[MAXN],sum[MAXN],net[MAXN],head[MAXN];
void add(int u,int v,int w,int ww){
    to[++tot]=v;cap[tot]=w;sum[tot]=ww;net[tot]=head[u];head[u]=tot;
    to[++tot]=u;cap[tot]=w;sum[tot]=ww;net[tot]=head[v];head[v]=tot;
}
int spfa(int s){
    memset(vis,0,sizeof(vis));
    memset(dis,0x7f,sizeof(dis));
    while(!que.empty())    que.pop();
    que.push(1);vis[1]=1;dis[1]=0;
    while(!que.empty()){
        int now=que.front();
        que.pop();vis[now]=0;
        for(int i=head[now];i;i=net[i])
            if(dis[to[i]]>dis[now]+cap[i]&&sum[i]>=s){
                dis[to[i]]=dis[now]+cap[i];
                if(!vis[to[i]]){
                    vis[to[i]]=1;
                    que.push(to[i]);
                }
            }
    }
}
int main(){
    scanf("%d%d%d",&n,&m,&x);
    for(int i=1;i<=m;i++){
        int u,v,L,C;
        scanf("%d%d%d%d",&u,&v,&L,&C);
        add(u,v,L,C);num[i]=C;
    }
    sort(num+1,num+1+m);
    int minn=0x7f7f7f7f;
    for(int i=1;i<=m;i++){
        spfa(num[i]);
        minn=min(minn,dis[n]+x/num[i]);
    }
    cout<<minn;
}

原文地址:https://www.cnblogs.com/cangT-Tlan/p/8965746.html

时间: 2024-10-12 13:14:21

洛谷 P3063 [USACO12DEC]牛奶的路由Milk Routing的相关文章

洛谷P3093 [USACO13DEC]牛奶调度Milk Scheduling

题目描述 Farmer John has N cows that need to be milked (1 <= N <= 10,000), each of which takes only one unit of time to milk. Being impatient animals, some cows will refuse to be milked if Farmer John waits too long to milk them. More specifically, cow

洛谷P2852 [USACO06DEC]牛奶模式Milk Patterns

题目描述 Farmer John has noticed that the quality of milk given by his cows varies from day to day. On further investigation, he discovered that although he can't predict the quality of milk from one day to the next, there are some regular patterns in th

洛谷 P1215 [USACO1.4]母亲的牛奶 Mother&#39;s Milk

题目描述 农民约翰有三个容量分别是A,B,C升的桶,A,B,C分别是三个从1到20的整数, 最初,A和B桶都是空的,而C桶是装满牛奶的.有时,农民把牛奶从一个桶倒到另一个桶中,直到被灌桶装满或原桶空了.当然每一次灌注都是完全的.由于节约,牛奶不会有丢失. 写一个程序去帮助农民找出当A桶是空的时候,C桶中牛奶所剩量的所有可能性. 输入输出格式 输入格式: 单独的一行包括三个整数A,B和C. 输出格式: 只有一行,升序地列出当A桶是空的时候,C桶牛奶所剩量的所有可能性. 输入输出样例 输入样例#1:

洛谷P3128 [USACO15DEC]最大流Max Flow

洛谷P3128 [USACO15DEC]最大流Max Flow 题目描述 FJ给他的牛棚的N(2≤N≤50,000)个隔间之间安装了N-1根管道,隔间编号从1到N.所有隔间都被管道连通了. FJ有K(1≤K≤100,000)条运输牛奶的路线,第i条路线从隔间si运输到隔间ti.一条运输路线会给它的两个端点处的隔间以及中间途径的所有隔间带来一个单位的运输压力,你需要计算压力最大的隔间的压力是多少. 输入输出格式 输入格式: The first line of the input contains

洛谷 P2709 BZOJ 3781 小B的询问

题目描述 小B有一个序列,包含N个1~K之间的整数.他一共有M个询问,每个询问给定一个区间[L..R],求Sigma(c(i)^2)的值,其中i的值从1到K,其中c(i)表示数字i在[L..R]中的重复次数.小B请你帮助他回答询问. 输入输出格式 输入格式: 第一行,三个整数N.M.K. 第二行,N个整数,表示小B的序列. 接下来的M行,每行两个整数L.R. 输出格式: M行,每行一个整数,其中第i行的整数表示第i个询问的答案. 输入输出样例 输入样例#1: 6 4 3 1 3 2 1 1 3

洛谷1231 教辅的组成

洛谷1231 教辅的组成 https://www.luogu.org/problem/show?pid=1231 题目背景 滚粗了的HansBug在收拾旧语文书,然而他发现了什么奇妙的东西. 题目描述 蒟蒻HansBug在一本语文书里面发现了一本答案,然而他却明明记得这书应该还包含一份练习题.然而出现在他眼前的书多得数不胜数,其中有书,有答案,有练习册.已知一个完整的书册均应该包含且仅包含一本书.一本练习册和一份答案,然而现在全都乱做了一团.许多书上面的字迹都已经模糊了,然而HansBug还是可

洛谷教主花园dp

洛谷-教主的花园-动态规划 题目描述 教主有着一个环形的花园,他想在花园周围均匀地种上n棵树,但是教主花园的土壤很特别,每个位置适合种的树都不一样,一些树可能会因为不适合这个位置的土壤而损失观赏价值. 教主最喜欢3种树,这3种树的高度分别为10,20,30.教主希望这一圈树种得有层次感,所以任何一个位置的树要比它相邻的两棵树的高度都高或者都低,并且在此条件下,教主想要你设计出一套方案,使得观赏价值之和最高. 输入输出格式 输入格式: 输入文件garden.in的第1行为一个正整数n,表示需要种的

洛谷 P2801 教主的魔法 题解

此文为博主原创题解,转载时请通知博主,并把原文链接放在正文醒目位置. 题目链接:https://www.luogu.org/problem/show?pid=2801 题目描述 教主最近学会了一种神奇的魔法,能够使人长高.于是他准备演示给XMYZ信息组每个英雄看.于是N个英雄们又一次聚集在了一起,这次他们排成了一列,被编号为1.2.…….N. 每个人的身高一开始都是不超过1000的正整数.教主的魔法每次可以把闭区间[L, R](1≤L≤R≤N)内的英雄的身高全部加上一个整数W.(虽然L=R时并不

洛谷P1466 集合 Subset Sums

洛谷P1466 集合 Subset Sums这题可以看成是背包问题 用空间为 1--n 的物品恰好填充总空间一半的空间 有几种方案 01 背包问题 1.注意因为两个交换一下算同一种方案,所以最终 要 f [ v ] / 2 2.要开 long long 1 #include <cstdio> 2 #include <cstdlib> 3 #include <cmath> 4 #include <cstring> 5 #include <string&g