洛谷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:考虑树上差分,对于一个点,在他那个位置++, ...
随机推荐
- 明解C语言 入门篇 第六章答案
练习6-1 /* 求两个整数中的最小值 */ #include <stdio.h> /*--- 返回三个整数中的最小值 ---*/ int min2(int a, int b) { int ...
- 【Oracle】重做undo表空间
重做undo表空间 场景: alert日志,报了如下错误: [oraprod@arpinfo bdump]$ tail -f alert_PROD.log Errors in file /ora115 ...
- Web应急:移动端劫持
PC端访问正常,移动端访问出现异常,比如插入弹窗.嵌入式广告和跳转到第三方网站,将干扰用户的正常使用,对用户体验造成极大伤害. 现象描述 部分网站用户反馈,手机打开网站就会跳转到赌博网站. 问题处理 ...
- 使用kibana给不同的用户创建不同的space
Elastic安全机制 在很多的情况下,出于安全的原因,我们需要对不同的Kibana用户分配不同的用户权限,这样使得他们之间不能互相访问彼此的资源,同 时他们也应该对不同的索引拥有不同的权限,比如读, ...
- Python模块File文件操作
Python模块File简介 Python提供了File模块进行文件的操作,他是Python的内置模块.我们在使用File模块的时候,必须先用Popen()函数打开一个文件,在使用结束需要close关 ...
- Kubernetes是什么东西?
Kubernetes一词来源于希腊语,翻译来的意思就是舵手或者船长的意思,而它的logo也是很符合这个词的 至于k8s则是通过将ubernetes这8个字母替换为8而导出的缩写 Kubernetes是 ...
- ES6入门系列 ----- 对象的遍历
工作中遍历对象是家常便饭了,遍历数组的方法五花八门, 然而很多小伙伴是不是和我之前一样只会用for ...in.... 来遍历对象呢, 今天给大家介绍五种遍历对象属性的方法: 1, 最常用的for ...
- Vue-cli构建spa应用
2.1 VUE-cli构建spa应用 npm install -g vue-cli Vue init webpack-simple demo vue init webpack demo2 如果在项目目 ...
- vue底部导航的精准显示
让底部导航只显示在一级页面: 路由中的写法: import Vue from 'vue' import Router from 'vue-router' //import HelloWorld fro ...
- ORACLE百分比分析函数RATIO_TO_REPORT() OVER()
有时候不用的指标的绝对值不能比,但是转转为百分比的形式就容易看出波动了,是数据分析的好用的一个分析函数 20:00:24 SYS@orcl> conn scott/tiger; Connecte ...