OpenJ_Bailian 2393

Yogurt factory

Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u

Submit Status Practice OpenJ_Bailian 2393

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周的时间生产一些单位的奶酪去销售。已知从第i(1<=i<=N)周生产一个单位奶酪的成本价格Ci和第i周的奶酪需求量Yi。奶酪可以储存,每单位的奶酪储存一周的花费为S,也就是说本周要销售的奶酪可以提前几周生产出来。问满足所有需求的最小成本是多少。

输入:

第一行N和S。之后N行是每一周的成本价和需求量。

输出:

最小成本。

分析:

使用贪心的思想。首先,第1周所需的奶酪必须要在第1周生产。之后的N-1周,每天需要的奶酪要么全部在当周生产,要么全部提前生产。如果当周生产比较省钱,那么当周的需求就在当周生产,并且假设如果之后的需求需要提前生产那么就在这一周生产,因为储存的价格是累周增加的。

 1 #include <cstdio>
 2 #define MAX_N 10000
 3 #define ll long long
 4 ll N,S,ans;
 5 struct week{ll p,need;}x[MAX_N + 1];
 6 int main(){
 7     scanf("%I64d%I64d",&N,&S);
 8     for(ll i = 0 ; i < N ; i++)
 9         scanf("%I64d%I64d",&x[i].p,&x[i].need);
10     ans = x[0].need * x[0].p;
11     ll index = 0;
12     for(ll i = 1 ; i < N ; i++){
13         ll pro_bef = x[index].p + S * (i - index),pro_now = x[i].p;
14         if(pro_bef < pro_now) ans += pro_bef * x[i].need;
15         else ans += pro_now * x[i].need,index = i;
16     }
17     printf("%lld\n",ans);
18     return 0;
19 }

时间: 2024-10-14 06:13:46

OpenJ_Bailian 2393的相关文章

四则运算表达式求值 OpenJ_Bailian - 4132

四则运算表达式求值 OpenJ_Bailian - 4132 题意:设计一个计算器,实现+-*/以及()的表达式运算求值. 栈的应用,这学期学数据结构,手写了栈练一下~ 1 #include <bits/stdc++.h> 2 using namespace std; 3 const int maxn=10010; //最大表达式长度 4 5 template <typename T> 6 class Stack; 7 8 template <typename T> 9

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

POJ 2393 Yogurt factory(简单贪心)

http://poj.org/problem?id=2393 题意:任务规定,一个酸奶制造厂,在n个星期内,分别要向外提供y[i]unit的酸奶.已知这个制造厂第i周制造每unit酸奶的费用为c[i],储存室储存每1unit酸奶1星期的费用为s.问要完成这个任务的最小费用是多少. . . . . . . . . . . . . . 思路:简单贪心.维护一个目前最优的代价minc = min(c, minc + s),然后求和. #include <iostream> using namespa

OpenJ_Bailian 1979

 Red and Black Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Submit Status Practice OpenJ_Bailian 1979 Description There is a rectangular room, covered with square tiles. Each tile is colored either red or black. A man

hdu 2393 Higher Math

Higher Math                                                                                  Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)                                                                          

OpenJ_Bailian 1852

 Ants Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Submit Status Practice OpenJ_Bailian 1852 Description An army of ants walk on a horizontal pole of length l cm, each with a constant speed of 1 cm/s. When a walking an

POJ 2393 Yogurt factory【贪心】

POJ 2393 题意: 每周可以生产牛奶,每周生产的价格为Ci,每周需要上交的牛奶量Yi,你可以选择本周生产牛奶,也可选择提前几周生产出存储在仓库中(仓库无限大,而且保质期不考虑),每一周存仓库牛奶需要花费S元,让你求出所有周的需求量上交的最少花费. 分析: 因为第 i 周的奶酪,可以在第 i 周生产,也可以在前几周生产,然后储存.通过把s转化为花费,跟原有花费去比较,取一个最小值,这样从头到尾,每一周都可以取得一个花费的最小值.贪心求解. #include<cstdio> #include

OpenJ_Bailian 1328

Radar Installation Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Submit Status Practice OpenJ_Bailian 1328 Description Assume the coasting is an infinite straight line. Land is in one side of coasting, sea in the other.

【BZOJ-1853&amp;2393】幸运数字&amp;Cirno的完美算数教室 容斥原理 + 爆搜 + 剪枝

1853: [Scoi2010]幸运数字 Time Limit: 2 Sec  Memory Limit: 64 MBSubmit: 1817  Solved: 665[Submit][Status][Discuss] Description 在中国,很多人都把6和8视为是幸运数字!lxhgww也这样认为,于是他定义自己的“幸运号码”是十进制表示中只包含数字6和8的那些号码,比如68,666,888都是“幸运号码”!但是这种“幸运号码”总是太少了,比如在[1,100]的区间内就只有6个(6,8,