SDNU——8题——D - Yogurt factory

Yucky Yogurt 生产调度优化
本文介绍了一个关于Yucky Yogurt工厂如何通过合理的生产计划来最小化成本的问题。通过对未来几周牛奶和劳动力价格波动的预测,采用贪心算法确定最佳生产策略,以满足每周需求并降低储存费用。
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.

 #include<cstdio>
 #include<iostream>
 #include<vector>
 #include<cmath>
 using namespace std;
 int main()
 {
 	int n,s,i;
 	long long int ret=0;
 	cin>>n>>s;

 	int price=9999;
 	int pricenow,put;
 	for(i=0;i<n;i++)
 	{
 		cin>>pricenow>>put;
 		price=min(pricenow,price+s);
 		ret+=price*put;
	 }
	 cout<<ret;
 }

这个题让我学到了很多

题目大意:输入今天的产奶价格和最少产奶量(可以多产存下来,但是存的时候也要花钱),问怎么控制产奶量使得花费最少~~

我一开始~~莽夫暴力——把今天价格和以后所有的价格相比(有个if跳出),麻烦是麻烦,但是能实现也好啊,那个存下来的价格+产奶价格和下一次价格的比较我就没能完美实现,(可能有点乱,那就别看我这个暴力思路了)

接下来是贪心算法——这个思路太棒了——费用只用和下一天的比,而起比较的是单价即可(今日单价比昨日单价+存储单价)如果大……就把今日价格更新为昨日单价+存储单价,然后与数量相乘得出目前最少花费~~

虽然只考虑一个方面,但就是又数学依据的——1.我们可以一天一天的算出最优单价,和最优花费,而且,会进行价格更新,无非就是两种情况{1}今天要生产的在昨天生产更值一些,那就把今天生产的价格,更新为昨天的价格加上单价(因为已经存了一天了),如果不值,就不必更新,直接,算出今天花费即可。又因为价格是更新的,所以可能第一天就会生产3的内容,因为最优价格是跟着天数走的~~(好好想一想,我可能说的有点乱了,希望能表达出我的点)没必要捆在一起考虑

2.相邻两天考虑的是:昨日:(昨日单价+存贮单价)*明日数量与明日单价*明日数量==》一约分你就会发现需要比较的就是单价

这就很考验数学了QAQ~~


评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值