Yogurt factory
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 6821   Accepted: 3488

Description

The cows have purchased a yogurt factory that makes world-famous Yucky Yogurt. Over the next N (1 <= N <= 10,000) weeks, the price of milk and labor will fluctuate weekly such that it will cost the company C_i (1 <= C_i <= 5,000) cents to produce one unit of
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

* Line 1: Two space-separated integers, N and S. 



* Lines 2..N+1: Line i+1 contains two space-separated integers: C_i and Y_i.

Output

* Line 1: Line 1 contains a single integer: the minimum total cost to satisfy the yogurt schedule. Note that the total might be too large for a 32-bit integer.

Sample Input

4 5
88 200
89 400
97 300
91 500

Sample Output

126900

Hint

OUTPUT DETAILS: 

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 【贪心】的更多相关文章

  1. poj-2393 Yogurt factory (贪心)

    http://poj.org/problem?id=2393 奶牛们有一个工厂用来生产奶酪,接下来的N周时间里,在第i周生产1 单元的奶酪需要花费ci,同时它们也有一个储存室,奶酪放在那永远不会坏,并 ...

  2. POJ-2393 Yogurt factory 贪心问题

    题目链接:https://cn.vjudge.net/problem/POJ-2393 题意 有一个生产酸奶的工厂,还有一个酸奶放在其中不会坏的储存室 每一单元酸奶存放价格为每周s元,在接下来的N周时 ...

  3. POJ 2393 Yogurt factory 贪心

    Description The cows have purchased a yogurt factory that makes world-famous Yucky Yogurt. Over the ...

  4. poj_2393 Yogurt factory 贪心

    Yogurt factory Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 16669   Accepted: 8176 D ...

  5. 百炼 POJ2393:Yogurt factory【把存储费用用递推的方式表达】

    2393:Yogurt factory 总时间限制:  1000ms 内存限制:  65536kB 描述 The cows have purchased a yogurt factory that m ...

  6. poj2393 Yogurt factory(贪心,思考)

    https://vjudge.net/problem/POJ-2393 因为仓储费是不变的. 对于每一周,要么用当周生产的,要么接着上一周使用的价格(不一定是输入的)加上固定的仓储费用. 应该算是用到 ...

  7. poj2393 Yogurt factory

    思路: 贪心. 实现: #include <iostream> #include <cstdio> #include <algorithm> using names ...

  8. Yogurt factory(POJ 2393 贪心 or DP)

    Yogurt factory Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 8205   Accepted: 4197 De ...

  9. 【BZOJ】1680: [Usaco2005 Mar]Yogurt factory(贪心)

    http://www.lydsy.com/JudgeOnline/problem.php?id=1680 看不懂英文.. 题意是有n天,第i天生产的费用是c[i],要生产y[i]个产品,可以用当天的也 ...

随机推荐

  1. Windows开源Web服务器性能和压力测试工具

    linux有很多开源工具用来测试服务器负载,而windows上非常少,几乎没有除了几个复杂的JMeter WET等 将两个好用的工具是Linux版本通过Cygwin移植过来,方便广大windows人员 ...

  2. 梦想MxWeb3D协同设计平台 2018.10.12更新

    SDK开发包下载地址: http://www.mxdraw.com/ndetail_10107.html 1. 全新的在线的三维协同设计平台,高效异步方式,基于JavaScript和WebGL技术,前 ...

  3. 11Java Server Pages 动作

    Java Server Pages 动作 JSP标准动作 分类 JSP标准动作 存取JavaBean相关 <jsp:useBean> <jsp:setProperty> < ...

  4. 实战:tcp链接rst场景tcpdump分析

    RST为重置报文段,它会导致TCP连接的快速拆迁,且不需要ack进行确认. 1.针对不存在的端口的连请求 客户端: #include <unistd.h> #include <sys ...

  5. NOIP 2008 传纸条(洛谷P1006,动态规划递推,滚动数组)

    题目链接:P1006 传纸条 PS:伤心,又想不出来,看了大神的题解 AC代码: #include<bits/stdc++.h> #define ll long long using na ...

  6. mysql外键是多个id组成的字符串,查询方法

    借鉴:mysql使用instr达到in(字符串)的效果 结论:select * from 表名where INSTR(CONCAT(字符串),CONCAT(表id)) 问题来源:一表中的某字段是另一表 ...

  7. 剑指offer---圆圈中最后剩下的数

    题目:圆圈中最后剩下的数 要求:0,1,2...n-1 共n个数排成一个圆圈,从数字0开始,每次删除第m个元素,求这个圆圈里面剩下的最后一个元素 如 n=5, m=3 的情况:0, 1, 2, 3, ...

  8. 关于ajax跨域请求API数据的一些问题

    一般来说我们使用jquery的ajax来跨域请求API数据的时候每次请求,就只能请求一组数据,而且当我们再次点击发送ajax请求的时候,新请求的数据会覆盖掉原来的数据,那么如何每次在请求的数据的时候, ...

  9. 2.8 补充:shell脚本执行方法

    bash shell 脚本的方法有多种,现在作个小结.假设我们编写好的shell脚本的文件名为hello.sh,文件位置在/data/shell目录中并已有执行权限.   方法一:切换到shell脚本 ...

  10. IIS部署网站只有首页能访问,其他链接失效/运行.net+Access网站-可能原因:IIS未启用32位应用程序模式

    在64位的机子上IIS运行32位的.NET程序 由于64位操作系统不支持Microsoft OLE DB Provider for Jet驱动程 也不支持更早的Microsoft Access Dri ...