洛谷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:考虑树上差分,对于一个点,在他那个位置++, ...
随机推荐
- tomcat启动项目报404错误
1.请求的时候报404错误,而且我的请求API地址是/account/sendSmsCode,从后台获取到的竟然变成了/account/account/sendSmsCode. 2.后来发现是 ...
- C/C++深度优先搜索(递归树模拟)
//C++深度优先搜索(递归树模拟) #define _CRT_SECURE_NO_WARNINGS #include <iostream> #define MAX_N 1000 usin ...
- AngularJS入门Demo
1 :表达式 <html> <head> <title>入门小Demo-1</title> <script src="angular.m ...
- Vue.js 源码分析(十四) 基础篇 组件 自定义事件详解
我们在开发组件时有时需要和父组件沟通,此时可以用自定义事件来实现 组件的事件分为自定义事件和原生事件,前者用于子组件给父组件发送消息的,后者用于在组件的根元素上直接监听一个原生事件,区别就是绑定原生事 ...
- Java内部类是如何实现的
内部类(inner class)是定义在另一个类中的类. 内部类方法可以访问该类定义所在的作用域中的数据,包括私有的数据. 内部类可以对同一个包中的其他类隐藏起来 当想定义一个回调函数且不想编写大量代 ...
- 一、hexo+github搭建个人博客的过程记录
前提: 1.新建一个github仓库 2.安装配置Node.js 3.安装配置Git 前提 步骤1.新建一个github仓库 打开github网站,(注册)登录账号,新建一个仓库; 注:==仓库名称要 ...
- 2019-11-29-C#-性能分析-反射-VS-配置文件-VS-预编译
原文:2019-11-29-C#-性能分析-反射-VS-配置文件-VS-预编译 title author date CreateTime categories C# 性能分析 反射 VS 配置文件 V ...
- PostgreSQL查询当前时间的时间戳
一.问题 使用PostgreSQL获取当前系统时间戳.众所周知,在MySQL中是这样的: select UNIX_TIMESTAMP(NOW()) 二.解决方案 (1)精确到秒 " (2)精 ...
- 通过Nginx获取用户真实IP
nginx配置 location / { proxy_set_header Host $host; proxy_set_header X-real-ip $remote_addr; proxy_set ...
- JavaScript之二十三种设计模式
23种JavaScript设计模式 原文链接:https://boostlog.io/@sonuton/23-javascript-design-patterns-5adb006847018500 ...