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.

 牛们收购了一个奶酪工厂,接下来的N个星期里,牛奶价格和劳力价格不断起伏.第i周,生产一个单位奶酪需要Ci(1≤Ci≤5000)便士.工厂有一个货栈,保存一单位奶酪,每周需要S(1≤S≤100)便士,这个费用不会变化.货栈十分强大,可以存无限量的奶酪,而且保证它们不变质.工厂接到订单,在第i周需要交付Yi(0≤Yi≤104)单位的奶酪给委托人.第i周刚生产的奶酪,以及之前的存货,都可以作为产品交付.请帮牛们计算这段时间里完成任务的最小代价.

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.

 
    第1行输入两个整数N和S.接下来N行输入Ci和Yi.

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.

    输出最少的代价.注意,可能超过32位长整型.

题解:

太经典了.

不难贪心证明,每次只可能用同一价格的存储方式.

我们只需维护一个 $minv$ ,表示价格最小值.

到下一周时,用 $minv[cur-1]$ 与 $cur_cost$ 作比较,并更新 $minv[i]$ 即可.

甚至都不用数组,几个变量即可搞定.

#include<bits/stdc++.h>
#define setIO(s) freopen(s".in","r",stdin)
#define ll long long
using namespace std;
int main()
{
// setIO("input");
int n;
ll s,c,y,cur=0,ans=0;
scanf("%d%lld",&n,&s);
scanf("%lld%lld",&c,&y);
ans+=c*y, cur=c;
for(int i=2;i<=n;++i)
{
scanf("%lld%lld",&c,&y);
cur=min(cur+s,c);
ans+=cur*y;
}
printf("%lld\n",ans);
return 0;
}

  

BZOJ 1740: [Usaco2005 mar]Yogurt factory 奶酪工厂 贪心 + 问题转化的更多相关文章

  1. 1740: [Usaco2005 mar]Yogurt factory 奶酪工厂

    1740: [Usaco2005 mar]Yogurt factory 奶酪工厂 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 119  Solved:  ...

  2. bzoj1680[Usaco2005 Mar]Yogurt factory*&&bzoj1740[Usaco2005 mar]Yogurt factory 奶酪工厂*

    bzoj1680[Usaco2005 Mar]Yogurt factory bzoj1740[Usaco2005 mar]Yogurt factory 奶酪工厂 题意: n个月,每月有一个酸奶需求量( ...

  3. [Usaco2005 mar]Yogurt factory 奶酪工厂

    接下来的N(1≤N10000)星期中,奶酪工厂在第i个星期要花C_i分来生产一个单位的奶酪.约克奶酪工厂拥有一个无限大的仓库,每个星期生产的多余的奶酪都会放在这里.而且每个星期存放一个单位的奶酪要花费 ...

  4. BZOJ1740: [Usaco2005 mar]Yogurt factory 奶酪工厂

    n<=10000天每天Ci块生产一东西,S块保存一天,每天要交Yi件东西,求最少花多少钱. 这个我都不知道归哪类了.. #include<stdio.h> #include<s ...

  5. BZOJ 1680 [Usaco2005 Mar]Yogurt factory:贪心【只用考虑上一个】

    题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1680 题意: 在接下来的n周内,第i周生产一吨酸奶的成本为c[i],订单为y[i]吨酸奶. ...

  6. bzoj 1680: [Usaco2005 Mar]Yogurt factory【贪心】

    贪心,一边读入一边更新mn,用mn更新答案,mn每次加s #include<iostream> #include<cstdio> using namespace std; in ...

  7. BZOJ1680: [Usaco2005 Mar]Yogurt factory

    1680: [Usaco2005 Mar]Yogurt factory Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 106  Solved: 74[Su ...

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

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

  9. BZOJ 1739: [Usaco2005 mar]Space Elevator 太空电梯

    题目 1739: [Usaco2005 mar]Space Elevator 太空电梯 Time Limit: 5 Sec  Memory Limit: 64 MB Description The c ...

随机推荐

  1. 最短路径--Floyd算法

    Floyd算法 1.定义概览 Floyd-Warshall算法(Floyd-Warshall algorithm)是解决任意两点间的最短路径的一种算法,可以正确处理有向图或负权的最短路径问题,同时也被 ...

  2. Blue Jeans POJ 3080 寻找多个串的最长相同子串

    Description The Genographic Project is a research partnership between IBM and The National Geographi ...

  3. code vs 2166 Bessie的体重问题

    2166 Bessie的体重问题  时间限制: 1 s  空间限制: 32000 KB  题目等级 : 黄金 Gold 题解       题目描述 Description Bessie像她的诸多姊妹一 ...

  4. TCP学习(3)--TCP释放连接的过程(四次挥手)

    一.TCP释放连接的过程(四次挥手)    TCP释放连接的步骤例如以下图所看到的.    如今如果clientA和server端B都处于数据传送状态. TCP连接断开的过程例如以下: 1.clien ...

  5. maven的启动类和MAVEN_OPTS参数

    maven的启动类和MAVEN_OPTS参数 在mvn.cmd的155行, set CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launc ...

  6. Java命名规则详细总结

    Class名应是首字母大写的名词.命名时应该使其简洁而又具有描述性.异常类的命名,应以Exception结尾.Interface的命名规则与Class相同 1. JAVA源文件的命名 JAVA源文件名 ...

  7. bzoj2132: 圈地计划(无比强大的最小割)

    2132: 圈地计划 题目:传送门 简要题意: 给出一个矩阵,一共n*m个点,并给出三个收益矩阵.A矩阵表示这个点建A的可取收益,B矩阵表示这个点建B的可取收益,C矩阵表示如果相邻(有且仅有一条公共边 ...

  8. Head First 设计模式 —— 策略设计模式

    创建一个能够根据所传递的参数对象的不同而具有不同行为(动态绑定的多态机制)的方法,被称为策略设计模式.

  9. ZOJ 2314 无源汇可行流(输出方案)

    Time Limit: 5 Seconds      Memory Limit: 32768 KB      Special Judge The terrorist group leaded by a ...

  10. Win7系统专栏

    1.去掉Win7快捷方式小箭头的方法如下: 使用普通方法会使系统出现异常,比如开始菜单程序无法删除.收藏夹无法展开等,网上流传使用透明图标的方法会在快捷方式上留下一块黑痣,下面的方法是小君研究出来的, ...