[Usaco2005 mar]Yogurt factory 奶酪工厂

接下来的N(1≤N10000)星期中,奶酪工厂在第i个星期要花C_i分来生产一个单位的奶酪。约克奶酪工厂拥有一个
无限大的仓库,每个星期生产的多余的奶酪都会放在这里。而且每个星期存放一个单位的奶酪要花费S分。工厂最
近收到了客戶N个星期的订单,第i个星期要向客戶提供Y_i 个单位的奶酪。当然这些奶酪可以在第i个星期时生产
,也可以从仓库中拿取。采用怎样的生产策略约克奶酪工厂的花费最小呢?
Input
第一行两个整数:N和S;接下来的N行中,第i行的两个数表示:C_i和Y_i。
Output
仅一行,即工厂生产的最小花费
Sample Input
4 5
88 200
89 400
97 300
91 500
Sample Output
126900

Sol:对于第i个月来说,要么当月生产。要么使用前面某个月,设为k,生产下来的
则对于第i+1个月来说要么当月生产要么使用前面某个月,则这个值仍等于前面的k,注意结果要用long long 保存

#include<cstdio>
int n,s,c,a;
long long now=10000000,ans=0;
int main()
{
	scanf("%d%d",&n,&s);//n个月,保管费用为s
	for (int i=1;i<=n;i++)
	{
		scanf("%d%d",&c,&a);//当月的成本为c,需求量为a
		if (now>c) //如果从[1,i-1]这一段某个月生产的成本高于本月的
		    now=c;//本月自己生产奶酪
		ans+=now*a;
		now+=s;//累加储存成本
	}
	printf("%lld",ans);
    return 0;
}

  

原文地址:https://www.cnblogs.com/cutemush/p/11679365.html

时间: 2024-11-06 20:20:27

[Usaco2005 mar]Yogurt factory 奶酪工厂的相关文章

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

1740: [Usaco2005 mar]Yogurt factory 奶酪工厂 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 119  Solved: 100[Submit][Status][Discuss] Description The cows have purchased a yogurt factory that makes world-famous Yucky Yogurt. Over the next N (1 <= N <= 10

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

n<=10000天每天Ci块生产一东西,S块保存一天,每天要交Yi件东西,求最少花多少钱. 这个我都不知道归哪类了.. 1 #include<stdio.h> 2 #include<string.h> 3 #include<stdlib.h> 4 #include<algorithm> 5 //#include<iostream> 6 using namespace std; 7 8 int n,m; 9 #define maxn 1001

bzoj 1680\1740 : [Usaco2005 Mar]Yogurt factory 贪心 双倍经验

1680: [Usaco2005 Mar]Yogurt factory 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 com

BZOJ1680: [Usaco2005 Mar]Yogurt factory

1680: [Usaco2005 Mar]Yogurt factory Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 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)

poj 2393 Yogurt Factory(贪心)

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) c

poj 2393 Yogurt factory

http://poj.org/problem?id=2393 Yogurt factory Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 7341   Accepted: 3757 Description The cows have purchased a yogurt factory that makes world-famous Yucky Yogurt. Over the next N (1 <= N <= 10

BZOJ 1738: [Usaco2005 mar]Ombrophobic Bovines 发抖的牛( floyd + 二分答案 + 最大流 )

一道水题WA了这么多次真是.... 统考终于完 ( 挂 ) 了...可以好好写题了... 先floyd跑出各个点的最短路 , 然后二分答案 m , 再建图. 每个 farm 拆成一个 cow 点和一个 shelter 点, 然后对于每个 farm x : S -> cow( x ) = cow( x ) 数量 , shelter( x ) -> T = shelter( x ) 容量 ; 对于每个dist( u , v ) <= m 的 cow( u ) -> shelter( v

1682: [Usaco2005 Mar]Out of Hay 干草危机

1682: [Usaco2005 Mar]Out of Hay 干草危机 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 391  Solved: 258[Submit][Status] Description The cows have run out of hay, a horrible event that must be remedied immediately. Bessie intends to visit the other farms

Factory Method 工厂方法模式

Factory method工厂方法模式是一种实现了“工厂”概念的面向对象设计模式.就像其他创建型模式一样,它也是处理在不指定对象具体类型的情况下创建对象的问题.工厂方法模式的实质是“定义一个创建对象的接口,但让实现这个接口的类来决定实例化哪个类.工厂方法让类的实例化推迟到子类中进行.” 创建一个对象常常需要复杂的过程,所以不适合包含在一个复合对象中.创建对象可能会导致大量的重复代码,可能会需要复合对象访问不到的信息,也可能提供不了足够级别的抽象,还可能并不是复合对象概念的一部分.工厂方法模式通