1680: [Usaco2005 Mar]Yogurt factory

Time Limit: 5 Sec  Memory Limit: 64 MB
Submit: 106  Solved: 74
[Submit][Status][Discuss]

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

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.

HINT

 

Source

题解:
刚看完题目,卧槽,这不是费用流吗?n=10000,瞬间蔫了。。。。。。。。
原来是贪心:
对于每一天可以从当天转移也可以从以前转移,只要保存一个以前的最小值,在这一天加一个s再跟c比较,更新完最小值直接更新答案。
水爆了。。。
代码:(copy)
 #include<cstdio>
inline int read()
{
int x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
int n,s,save=;
long long ans;
int main()
{
n=read();
s=read();
for (int i=;i<=n;i++)
{
int w=read(),c=read();
save+=s;
if (save>w)save=w;
ans+=(long long)save*c;
}
printf("%lld",ans);
}

BZOJ1680: [Usaco2005 Mar]Yogurt factory的更多相关文章

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

  9. poj 2393 Yogurt factory

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

随机推荐

  1. java类的加载顺序

    related URL: http://www.cnblogs.com/guoyuqiangf8/archive/2012/10/31/2748909.html Parent Class: packa ...

  2. (转)How to build an Apple Push Notification provider server (tutorial)

    转自:https://blog.serverdensity.com/how-to-build-an-apple-push-notification-provider-server-tutorial/ ...

  3. lesson4:利用jmeter来压测数据库

    本文讲述了如何利用jmeter来压测数据库,事例中选取了mysql作为测试数据库,其它的数据库也是一样,只需要更换驱动程序即可. 准备工作:a.mysql数据库安装,请自行百度:b.jdbc驱动包,请 ...

  4. 轻量级mvvm Web开发框架 postby:http://zhutty.cnblogs.com

    今天特别郁闷,怎么说呢,之前一直就用angular,然后这两天用的是avalon这东西,反正,一开始没时间去玩它,第一个任务就是封装个jq插件,实现一个小功能.反正呢,就是越写越郁闷.用过angula ...

  5. 继承PictureBox显示GIF的自定义控件实现

    处理GIF部分 using System; using System.Collections.Generic; using System.Linq; using System.Text; using ...

  6. [置顶] SQL注入问题

    我们做系统,有没有想过,自己的容量很大的一个数据库就被很轻易的进入,并删除,是不是很恐怖的一件事.这就是sql注入. 一.SQL注入的概念         SQL注入攻击指的是通过构建特殊的输入作为参 ...

  7. rac 10g 加入节点具体解释

    目标: 当前我环境中是有两个节点RAC1和RAC2 节点.如今添加一个RAC3节点.   概要:为现有的Oracle10g RAC 加入节点大致包含下面步骤: 1. 配置新的server节点上的硬件及 ...

  8. Linux下查看显卡型号

    查看显卡使用 lspci |grep VGAemos@emos-desktop:~$ lspci -vnn | grep -i vga00:02.0 VGA compatible controller ...

  9. BFC——块级格式上下文

    BFC中的B指的是block,对应的还有IFC,I指的是inline.对于BFC的理解可以参考层叠上下文.页面中,盒子的排布规则,是生效在对应的BFC中.两个BFC中的布局互不影响.页面的本身的根本身 ...

  10. C#类的基本用法

    Preson类 using System; using System.Collections.Generic; using System.Linq; using System.Text; using ...