Greedy:Yogurt factory(POJ 2393)

题目大意:酸奶工厂每个星期都要制造酸奶,成本每单位x,然后每个星期要生产y,然后酸奶厂有个巨大的储存室,可以无限储存酸奶,而且酸奶的品质不会变坏,每天储存要每单位花费S,求最小的成本。
简直是初中生数学题,贪心法即可,假如当前酸奶成本是X,则如果储存酸奶,则下k个星期的(如果还使用这批酸奶),则成本为x+k*s,对比k个星期的成本就可以确定用哪个了。
水题
#include <iostream>
#include <functional>
#include <algorithm> typedef struct demand
{
int cost;
int units;
}Week; Week work[]; void Search(const int, const int); int main(void)
{
int N, S;
while (~scanf("%d%d", &N, &S))
{
for (int i = ; i < N; i++)
scanf("%d%d", &work[i].cost, &work[i].units);
Search(N, S);
}
return ;
} void Search(const int N, const int S)
{
int stop, now_cost, j;
long long ans = ; for (int pos = ; pos < N; )
{
now_cost = work[pos].cost;
for (stop = pos + , j = ; stop < N && now_cost + j*S < work[stop].cost; j++, stop++); for (int k = ; k < j; k++)//i是当前位置
ans += (long long)((now_cost + S*k) * work[pos + k].units);
pos = stop;
}
printf("%lld\n", ans);
}

Greedy:Yogurt factory(POJ 2393)的更多相关文章
- poj 2393 Yogurt factory
http://poj.org/problem?id=2393 Yogurt factory Time Limit: 1000MS Memory Limit: 65536K Total Submis ...
- Yogurt factory(POJ 2393 贪心 or DP)
Yogurt factory Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 8205 Accepted: 4197 De ...
- POJ 2393 Yogurt factory 贪心
Description The cows have purchased a yogurt factory that makes world-famous Yucky Yogurt. Over the ...
- POJ 2393 Yogurt factory【贪心】
POJ 2393 题意: 每周可以生产牛奶,每周生产的价格为Ci,每周需要上交的牛奶量Yi,你可以选择本周生产牛奶,也可选择提前几周生产出存储在仓库中(仓库无限大,而且保质期不考虑),每一周存仓库牛奶 ...
- 百炼 POJ2393:Yogurt factory【把存储费用用递推的方式表达】
2393:Yogurt factory 总时间限制: 1000ms 内存限制: 65536kB 描述 The cows have purchased a yogurt factory that m ...
- BZOJ1680: [Usaco2005 Mar]Yogurt factory
1680: [Usaco2005 Mar]Yogurt factory Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 106 Solved: 74[Su ...
- 1740: [Usaco2005 mar]Yogurt factory 奶酪工厂
1740: [Usaco2005 mar]Yogurt factory 奶酪工厂 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 119 Solved: ...
- C - Yogurt factory
The cows have purchased a yogurt factory that makes world-famous Yucky Yogurt. Over the next N (1 &l ...
- Yogurt factory
Description The cows have purchased a yogurt factory that makes world-famous Yucky Yogurt. Over the ...
随机推荐
- 解决already defined in .obj 的问题(定义/声明的区别)
首先需要搞清楚什么是定义(definition ),什么是声明(declaration). 一.函数 函数的声明: int myfunc(int a,int b); 定义: int myfunc(in ...
- 【HDU 4150】Powerful Incantation
题 题意 给你s1,s2两个字符串,求s1中有多少个s2 代码 #include<stdio.h> #include<string.h> int t,len1,len2,pos ...
- BZOJ-3227 红黑树(tree) 树形DP
个人认为比较好的(高端)树形DP,也有可能是人傻 3227: [Sdoi2008]红黑树(tree) Time Limit: 10 Sec Memory Limit: 128 MB Submit: 1 ...
- java订电影票系统
public class Test { public static void main(String[] args) { BookTicket bookTicket = new BookTicket( ...
- php验证是否是中文
header("content-type:text/html;charset=utf-8");$str = "编";if (preg_match("/ ...
- Linux 磁盘分区
原文地址:http://www.jb51.net/LINUXjishu/57192.html 磁头数(Heads)表示硬盘总共有几个磁头,也就是有几面盘片, 最大为 255 (用 8 个二进制位存储) ...
- int(11)最大长度是多少,MySQL中varchar最大长度是多少(转)
int(11)最大长度是多少,MySQL中varchar最大长度是多少? int(11)最大长度是多少? 在SQL语句中int代表你要创建字段的类型,int代表整型,11代表字段的长度. 这个11代表 ...
- ASP.NET MVC 开启AJAX跨域请求
<system.webServer> <httpProtocol> <customHeaders> <add name="Access-Contro ...
- Cannot find class [org.apache.commons.dbcp.BasicDataSource]
错误:Cannot find class [org.apache.commons.dbcp.BasicDataSource] 原因:缺少commons-dbcp.jar
- glibc 简介:
glibc 编辑 glibc是GNU发布的libc库,即c运行库.glibc是linux系统中最底层的api,几乎其它任何运行库都会依赖于glibc.glibc除了封装linux操作系统所提供的系统服 ...