洛谷P3063 [USACO12DEC]牛奶的路由Milk Routing
其实在博客园里写题解都挺应付的都是在洛谷写了之后
挑一部分粘过来
在洛谷写的也都是废话,是为了凑篇幅
主要就是代码
大体思路就一提
这题贪心不行废话
跑m遍SPFA更新最小值
注意数组记得清空
The Last:
#include <queue>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
const int N = ;
int cnt, head[N << ], n, m, x, minn = 0x3f3f3f3f, C[N], t, s, dis[N];
bool vis[N];
struct node{
int nxt, to, d, w;
}e[N << ];
int read() {
int s = , w = ;
char ch = getchar();
while(!isdigit(ch)) {if(ch == '-') w = -; ch = getchar();}
while(isdigit(ch)) {s = s * + ch - ''; ch = getchar();}
return s * w;
}
void add(int x, int y, int w, int d) {
e[++cnt].nxt = head[x];
e[cnt].to = y;
e[cnt].w = w;
e[cnt].d = d;
head[x] = cnt;
}
void spfa (int ww) {
queue<int> q;
memset(dis, , sizeof(dis));
memset(vis, , sizeof(vis));
vis[] = ;
q.push();
dis[] = ;
while (!q.empty()) {
int he = q.front();
q.pop();
vis[he] = ;
for (int i = head[he]; i ;i = e[i].nxt) {
if (dis[e[i].to] > dis[he] + e[i].d && e[i].w >= ww) {
dis[e[i].to] = dis[he] + e[i].d;
if (!vis[e[i].to]) {
vis[e[i].to] = ;
q.push(e[i].to);
}
}
}
}
}
int main() {
n = read(), m = read(), x = read();
for(int i = ; i <= m; i++) {
int x, y, d, l;
x = read(), y = read(), d = read(), l = read();
add(x, y, l, d), add(y, x, l, d);
C[i] = l;
}
// for(int i = 1; i <= n; i++)
// printf("%d ", e[i].w);
// printf("\n");
// sort(C + 1, C + 1 + m);
for(int i = ; i <= m; i++) {
spfa(C[i]);
minn = min(minn, (dis[n] + x / C[i]));
}
// for(int i = 1; i <= n; i++)
// printf("%d ", dis[i]);
// printf("\n");
printf("%d\n", minn);
return ;
}
谢谢收看,祝身体健康!
洛谷P3063 [USACO12DEC]牛奶的路由Milk Routing的更多相关文章
- 洛谷 P3063 [USACO12DEC]牛奶的路由Milk Routing
P3063 [USACO12DEC]牛奶的路由Milk Routing 题目背景 征求翻译.如果你能提供翻译或者题意简述,请直接发讨论,感谢你的贡献. 题目描述 Farmer John's farm ...
- 【luogu P3063 [USACO12DEC]牛奶的路由Milk Routing】 题解
题目链接:https://www.luogu.org/problemnew/show/P3063#sub 我很好奇这道题为什么没被收入SPFA好题 #include <cstdio> #i ...
- [洛谷P2852] [USACO06DEC]牛奶模式Milk Patterns
洛谷题目链接:[USACO06DEC]牛奶模式Milk Patterns 题目描述 Farmer John has noticed that the quality of milk given by ...
- 洛谷 P3063 【[USACO12DEC]Milk Routing S】
这道题可以暴力哒~ 我们枚举每一个出现过的容量,然后跑一次最短路,求延迟,在跑最短路的时候,如果遇到的某一个点,比我们当前枚举的那个点小,那么就直接不走这一个点,然后枚举完后,就能得到最大值了. 代码 ...
- 洛谷P3093 [USACO13DEC]牛奶调度Milk Scheduling
题目描述 Farmer John has N cows that need to be milked (1 <= N <= 10,000), each of which takes onl ...
- 洛谷P1208——P1208 [USACO1.3]Mixing Milk(贪心)
题目描述 由于乳制品产业利润很低,所以降低原材料(牛奶)价格就变得十分重要.帮助Marry乳业找到最优的牛奶采购方案. Marry乳业从一些奶农手中采购牛奶,并且每一位奶农为乳制品加工企业提供的价格是 ...
- 洛谷 P1208混合牛奶【贪心】
题目描述 由于乳制品产业利润很低,所以降低原材料(牛奶)价格就变得十分重要.帮助Marry乳业找到最优的牛奶采购方案. Marry乳业从一些奶农手中采购牛奶,并且每一位奶农为乳制品加工企业提供的价格是 ...
- 洛谷P3065 [USACO12DEC]第一!First!(Trie树+拓扑排序)
P3065 [USACO12DEC]第一!First! 题目链接:https://www.luogu.org/problemnew/show/P3065 题目描述 Bessie一直在研究字符串.她发现 ...
- 洛谷P3066 [USACO12DEC]逃跑的BarnRunning Away From…
题面链接 一句话题意:给出以1号点为根的一棵有根树,问每个点的子树中与它距离小于等于l的点有多少个. 我:似乎并不好做啊...看了题解后大雾... sol:考虑树上差分,对于一个点,在他那个位置++, ...
随机推荐
- 【记录】【idea】【mysql】Server returns invalid timezone. Go to 'Advanced' tab and set 'serverTimezone' property manually.解决问题
idea连接mysql报错Server returns invalid timezone. Go to 'Advanced' tab and set 'serverTimezone' property ...
- Salesforce学习之路(二)Profile
如上篇文章所述,针对User来讲,最重要的概念便是Profile和Role,因为Profile于Security息息相关,这是一个合格的产品中十分重要的一环. 何为Profile? 前文所讲--就是一 ...
- Istio开启mtls请求503问题分析
背景 为测试Istio流量管理,将两个服务sleep.flaskapp的两个版本v1.v2(部署文件见参考链接)部署到Istio环境中,通过sleep-v1向flaskapp发起调用http://fl ...
- SQL Server ---------- 分离数据库 生成 .mdf文件
1.首先查看你要分离的数据库存储的位置 选中需要分离的数据数据库右击鼠标点击属性 要是记不住建议 复制一下 2.分离数据库 生成 .mdf 文件 右击 -----> 任务 -- ...
- WebSocket的简单认识&SpringBoot整合websocket
1. 什么是WebSocket?菜鸟对websocket的解释如下 WebSocket 是 HTML5 开始提供的一种在单个 TCP 连接上进行全双工通讯的协议. WebSocket 使得客户端和服务 ...
- 极简 Spring Boot 整合 Thymeleaf 页面模板
虽然现在慢慢在流行前后端分离开发,但是据松哥所了解到的,还是有一些公司在做前后端不分的开发,而在前后端不分的开发中,我们就会需要后端页面模板(实际上,即使前后端分离,也会在一些场景下需要使用页面模板, ...
- Gordon家族(二)
本文是 Gordon家族(一) 的续集. 16. GoLearn 介绍:Gordon博士为Go开发者提供了一系列机器学习的库,开箱即用. 地址:https://github.com/sjwhitwor ...
- go 中string[0]到底是rune还是byte?
好像没区别,对吧? 来看个全面的对比: package main import ( "fmt" "reflect") func main(){ asci:=&q ...
- babel plugin和presets是什么,怎么用?
https://www.fullstackreact.com/articles/what-are-babel-plugins-and-presets/ 当开发react或者vuejs app时,开发者 ...
- Java线程安全面试题,你真的了解吗?
多个线程不管以何种方式访问某个类,并且在主调代码中不需要进行同步,都能表现正确的行为. 线程安全有以下几种实现方式: 不可变 不可变(Immutable)的对象一定是线程安全的,不需要再采取任何的线程 ...