POJ2393 Yogurt factory 【贪心】
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 6821 | Accepted: 3488 |
Description
yogurt in week i. Yucky's factory, being well-designed, can produce arbitrarily many units of yogurt each week.
Yucky Yogurt owns a warehouse that can store unused yogurt at a constant fee of S (1 <= S <= 100) cents per unit of yogurt per week. Fortuitously, yogurt does not spoil. Yucky Yogurt's warehouse is enormous, so it can hold arbitrarily many units of yogurt.
Yucky wants to find a way to make weekly deliveries of Y_i (0 <= Y_i <= 10,000) units of yogurt to its clientele (Y_i is the delivery quantity in week i). Help Yucky minimize its costs over the entire N-week period. Yogurt produced in week i, as well as any
yogurt already in storage, can be used to meet Yucky's demand for that week.
Input
* Lines 2..N+1: Line i+1 contains two space-separated integers: C_i and Y_i.
Output
Sample Input
4 5
88 200
89 400
97 300
91 500
Sample Output
126900
Hint
In week 1, produce 200 units of yogurt and deliver all of it. In week 2, produce 700 units: deliver 400 units while storing 300 units. In week 3, deliver the 300 units that were stored. In week 4, produce and deliver 500 units.
Source
每次更新相邻的下一周就可以。由于若下一周被更新,那么下一周能够用来更新剩下的周,所以当前周仅仅须要负责下一周。
#include <stdio.h>
#include <string.h> #define maxn 10002 int min(int a, int b) {
return a < b ? a : b;
} int X[maxn], Y[maxn]; int main() {
int N, S, i, j;
__int64 sum;
while(scanf("%d%d", &N, &S) == 2) {
for(i = 0; i < N; ++i)
scanf("%d%d", &X[i], &Y[i]);
for(i = sum = 0; i < N; ++i) {
sum += X[i] * Y[i];
if(i != N - 1)
X[i+1] = min(X[i+1], X[i] + S);
}
printf("%I64d\n", sum);
}
return 0;
}
2014-12-1更新
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <queue>
using namespace std;
typedef long long LL; LL ans; int main() {
int N, S, i, c, m, pre;
scanf("%d%d", &N, &S);
scanf("%d%d", &c, &m);
pre = c + S; // 仓库价格
ans += c * m;
while(--N) {
scanf("%d%d", &c, &m);
if(pre < c) c = pre;
else pre = c;
ans += c * m;
pre += S;
}
printf("%lld\n", ans);
return 0;
}
POJ2393 Yogurt factory 【贪心】的更多相关文章
- poj-2393 Yogurt factory (贪心)
http://poj.org/problem?id=2393 奶牛们有一个工厂用来生产奶酪,接下来的N周时间里,在第i周生产1 单元的奶酪需要花费ci,同时它们也有一个储存室,奶酪放在那永远不会坏,并 ...
- POJ-2393 Yogurt factory 贪心问题
题目链接:https://cn.vjudge.net/problem/POJ-2393 题意 有一个生产酸奶的工厂,还有一个酸奶放在其中不会坏的储存室 每一单元酸奶存放价格为每周s元,在接下来的N周时 ...
- POJ 2393 Yogurt factory 贪心
Description The cows have purchased a yogurt factory that makes world-famous Yucky Yogurt. Over the ...
- poj_2393 Yogurt factory 贪心
Yogurt factory Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 16669 Accepted: 8176 D ...
- 百炼 POJ2393:Yogurt factory【把存储费用用递推的方式表达】
2393:Yogurt factory 总时间限制: 1000ms 内存限制: 65536kB 描述 The cows have purchased a yogurt factory that m ...
- poj2393 Yogurt factory(贪心,思考)
https://vjudge.net/problem/POJ-2393 因为仓储费是不变的. 对于每一周,要么用当周生产的,要么接着上一周使用的价格(不一定是输入的)加上固定的仓储费用. 应该算是用到 ...
- poj2393 Yogurt factory
思路: 贪心. 实现: #include <iostream> #include <cstdio> #include <algorithm> using names ...
- Yogurt factory(POJ 2393 贪心 or DP)
Yogurt factory Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 8205 Accepted: 4197 De ...
- 【BZOJ】1680: [Usaco2005 Mar]Yogurt factory(贪心)
http://www.lydsy.com/JudgeOnline/problem.php?id=1680 看不懂英文.. 题意是有n天,第i天生产的费用是c[i],要生产y[i]个产品,可以用当天的也 ...
随机推荐
- MySQL——基本安装与使用
基本安装 下载地址:https://dev.mysql.com/downloads/mysql/ 选择解压版本:mysql-5.7.21-winx64.zip 以管理员身份打开cmd(除了安装服务不要 ...
- [转]汇编语言:MOVSB,MOVSW,MOVSD
汇编语言:MOVSB,MOVSW,MOVSD 转自: http://blog.csdn.net/zhenyongyuan123/article/details/8364011 目前80386系列的 ...
- 从输入URL到网页呈现的过程
1.域名解析当我们在浏览器中输入一个URL,例如”www.google.com”时,这个地址并不是谷歌网站真正意义上的地址.互联网上每一台计算机的唯一标识是它的IP地址,因此我们输入的网址首先需要先解 ...
- Eigen库笔记整理(二)
Eigen/Geometry 模块提供了各种旋转和平移的表示 旋转矩阵直接使用 Matrix3d 或 Matrix3f Eigen::Matrix3d rotation_matrix = Eigen: ...
- 【转载】Java下利用Jackson进行JSON解析和序列化
参考资料: https://blog.csdn.net/sdut406/article/details/85647982 Java下常见的Json类库有Gson.JSON-lib和Jackson等,J ...
- jquery 实现点评标签 类似淘宝大众点评的 快速准时 货品完好等
111 <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <tit ...
- 关于SPFA的双端队列优化
7.11 Update 我做题的时候发现这样写会RE 因为在使用双端队列优化SPFA的时候 在将一个点加入队列的时候,如果队列已经空了 那么一旦出现dis[Q.front()]就会RE 可以这样修改 ...
- 利用postman进行接口测试并发送带cookie请求的方法
做web测试的基本上都用用到postman去做一些接口测试,比如测试接口的访问权限,对于某些接口用户A可以访问,用户B不能访问:比如有时需要读取文件的数据.在postman上要实现这样测试,我们就必要 ...
- 作为一个程序员,分享一下我自己常用的几款非常方便的chrome插件
作为一名资深码农,结合身边一群IT民工的真实体验,小编有那么一点权威给各位推荐几款程序员必备.常用的chrome扩展插件. 1.Click&Clean Click&Clean插件可以监 ...
- spring 学习(二)
public interface BeanPostProcessor { @Nullable default Object postProcessBeforeInitialization(Object ...