POJ 2393 Yogurt factory【贪心】

POJ 2393

题意:

每周可以生产牛奶,每周生产的价格为Ci,每周需要上交的牛奶量Yi,你可以选择本周生产牛奶,也可选择提前几周生产出存储在仓库中(仓库无限大,而且保质期不考虑),每一周存仓库牛奶需要花费S元,让你求出所有周的需求量上交的最少花费。

分析:

因为第 i 周的奶酪,可以在第 i 周生产,也可以在前几周生产,然后储存。通过把s转化为花费,跟原有花费去比较,取一个最小值,这样从头到尾,每一周都可以取得一个花费的最小值。贪心求解。

#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<queue>
using namespace std;
const int maxn=10011;
int n,s;
int y[maxn],c[maxn];
int main()
{
    while(scanf("%d%d",&n,&s)!=EOF)
    {
        for(int i=0;i<n;i++)
            scanf("%d%d",&c[i],&y[i]);
        long long ans=0;
        for(int i=1;i<n;i++)
            c[i]=min(c[i-1]+s,c[i]);
        for(int i=0;i<n;i++)
            ans+=c[i]*y[i];
        printf("%lld\n",ans);
    }
    return 0;
}
时间: 2024-10-19 19:26:01

POJ 2393 Yogurt factory【贪心】的相关文章

poj 2393 Yogurt factory(贪心)

传送门 解题思路 对于第\(i\)周来说,最小的花费 \(sum=min(y[i]*(c[j]+s(i-j)))(1<=j<=i)\),所以\(sum=min(y[i]*(c[j]-s[j]+s[i])\),发现\(y[i]\)与\(s[i]\)均为定值,就是让最小化\(c[j]-s[j]\),然后就直接维护个最小值每次更新答案即可. 代码 #include<iostream> #include<cstdio> #include<cstring> #incl

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

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

贪心问题 POJ 2393 Yogurt factory

题目:http://poj.org/problem?id=2393 题意:N周,每周生成牛奶(任意!),每周成本为c_i(1~5000),每周出货 y_i:出货可以使用该周生产的,也可以用之前的储存的牛奶,每周存储 每单位牛奶需要 S 价格.问,N周最小的成本是多少? 题解:贪心策略,维持每周 的最低单位成本,本周的单位成本 为 min(上周单位成本 + 存储S,本周成本) AC代码: #include <iostream> #include <cstdio> #include &

poj 2393 Yogurt factory(dp+贪心)

奶牛们建了一家酸奶厂,在N周内每周需要出货Y_i单位酸奶,第i周成本为C_i,储存费为每周S.求总体最低成本. 贪心策略是维持每周的最低单位成本,每周可能用上周剩下的,也可能生产新的.于是该周单位成本可能为上一周的单位成本加上储存费,也可能为该周的单位成本. 1 #pragma comment(linker, "/STACK:1024000000,1024000000") 2 #include<iostream> 3 #include<cstdio> 4 #in

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

poj_2393 Yogurt factory 贪心

Yogurt factory Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 16669   Accepted: 8176 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

poj Yogurt factory (贪心水题)

# include <stdio.h> # include <string.h> # include <algorithm> using namespace std; int main() { int i,n,s; __int64 sum ; int cost[10010],num[10010]; while(~scanf("%d%d",&n,&s)) { for(i=0;i<n;i++) scanf("%d%d&qu