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. 
 
 
题目意思:由于市场原因牛奶的生产价格会有所波动,要求在将来的n周里,该公司拥有一个足够大的仓库储存制好的牛奶,每个单位的牛奶每周储存

 所需的费用为s,现给出将来n周生产每单位牛奶的价格及客户所需的数量(即提前知道了下面几周的牛奶价格和客户需求!!!),求出该公司将来n周内所要支付的最小生产值。
 
解题思路:这是一道贪心题,贪心策略,每一个周只需要和下一个周对比,每一次更新下一个相邻的周,因为若下一个周被更新了,那么下一个周可以用来更新剩下的周,所以每一个周只需要对下一个周负责就可以了,可以看成一种带有传递性的比较。
 
上代码:

 #include<stdio.h>
struct Yogurt
{
int c;
int y;
};
int main()
{
int n,s,i;
long long ans;
struct Yogurt a[];
a[].c=;
while(scanf("%d%d",&n,&s)!=EOF)
{
for(i=; i<=n; i++)
{
scanf("%d%d",&a[i].c,&a[i].y);
}
for(i=; i<=n; i++)
{
if(a[i].c<a[i-].c+s)
a[i].c=a[i].c;
else
a[i].c=a[i-].c+s;
}
ans=;
for(i=; i<=n; i++)
{
ans=ans+a[i].c*a[i].y;
}
printf("%lld\n",ans);
}
return ;
}

Yogurt factory的更多相关文章

  1. poj 2393 Yogurt factory

    http://poj.org/problem?id=2393 Yogurt factory Time Limit: 1000MS   Memory Limit: 65536K Total Submis ...

  2. BZOJ1680: [Usaco2005 Mar]Yogurt factory

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

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

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

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

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

  5. POJ 2393 Yogurt factory 贪心

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

  6. C - Yogurt factory

    The cows have purchased a yogurt factory that makes world-famous Yucky Yogurt. Over the next N (1 &l ...

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

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

  8. POJ2393 Yogurt factory 【贪心】

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

  9. BZOJ 1740: [Usaco2005 mar]Yogurt factory 奶酪工厂 贪心 + 问题转化

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

随机推荐

  1. Storm相关笔记(包括Kafka和HBase)

    一.Apache Kafka 1.了解Kafka 1.1.Kafka是什么?有什么用? 是什么? 1) Apache Kafka 是一个消息队列(生产者消费者模式) 2) Apache Kafka 目 ...

  2. mysql的索引和执行计划

    一.mysql的索引 索引是帮助mysql高效获取数据的数据结构.本质:索引是数据结构 1:索引分类 普通索引:一个索引只包含单个列,一个表可以有多个单列索引. 唯一索引:索引列的值必须唯一 ,但允许 ...

  3. ubuntu服务器安装jupyter notebook, 并能够实现本地远程连接

    1.terminal 敲击 pip3 install jupyter 2.terminal 敲击 jupyter notebook --generate-config 3.terminal 敲击 py ...

  4. 一张图一个表——CSS选择器总结

    CSS选择器总结: (这些表是一张图片^_^) 看底部 完整思维导图图片和表格的下载地址:https://download.csdn.net/download/denlnyyr/10597820 (我 ...

  5. 用户从地址栏输入url,按下enter键后,直到页面加载完成的这个过程都发生了什么?

    流程大概描述一下: 用户将url输入后,服务器接受到请求,然后将这个请求进行处理,然后将处理后的结果返回给浏览器,浏览器将该结果以页面的形式呈现给用户. 详细描述: 1:用户将url(例如www.ba ...

  6. 将Windows 7安装到移动固态硬盘(U盘)

    由于工作的原因,有时需要用两台电脑工作,而搞开发的人大多又是追求计算机性能的人,所以笔记本电脑自然不轻,更何况两台. 两台电脑折磨我半年多,终于下定决心将个系统安装到移动固态硬盘中,背一台无硬盘电脑加 ...

  7. 树莓派3B+学习笔记:11、查看硬件信息

    1.查看CPU信息 cat /proc/cpuinfo 查看最后三行 如果只想查看最后三行,也可使用这个命令 /proc/cpuinfo lscpu 2.查看树莓派型号 cat /proc/devic ...

  8. Shellz中awk的简单用法

    其实shell脚本的功能常常被低估.在实际应用中awk sed 等用法可以为shell提供更为强大的功能.下面我们将一下awk调用的简单方法进行了总结.方便同学们学习: awk的简单用法: 第一种调用 ...

  9. nodejs fastdfs

    node端fastdfs客户端上传文件 var FdfsClient = require('fdfs'); var fdfs = new FdfsClient({ // tracker servers ...

  10. Linux入门——基础系统设置命令

    以下为centos7实验环境 1.网卡管理工具命令——nmcli 参考:http://www.iteye.com/topic/1141839 2.主机名称设置——hostnamectl [root@s ...