poj_2393 Yogurt factory 贪心
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 16669 | Accepted: 8176 |
Description
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
* Lines 2..N+1: Line i+1 contains two space-separated integers: C_i and Y_i.
Output
Sample Input
4 5
88 200
89 400
97 300
91 500
Sample Output
126900
Hint
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.
看了几篇博客才有了点思路, 每天生产的酸奶是那一天的,要比较今天的 C 与 Cmin + S 的关系, Cmin是前几个周存储在仓库里的酸奶最小成本, 随着时间的推移,Cin+S , 直到他不再小于当前的C, 替换掉。
#include <iostream>
#include <stdio.h> using namespace std; int main()
{
long long ans;
int n, s, y, c, minc;
while(scanf("%d%d", &n, &s)!=-)
{
ans=; minc=;
for(int i=; i<n; i++)
{
scanf("%d%d", &c, &y);
if(c > minc +s)
c = minc + s;
minc = c;
ans += c*y;
}
printf("%lld\n", ans);
}
return ;
}
poj_2393 Yogurt factory 贪心的更多相关文章
- POJ 2393 Yogurt factory 贪心
Description The cows have purchased a yogurt factory that makes world-famous Yucky Yogurt. Over the ...
- poj-2393 Yogurt factory (贪心)
http://poj.org/problem?id=2393 奶牛们有一个工厂用来生产奶酪,接下来的N周时间里,在第i周生产1 单元的奶酪需要花费ci,同时它们也有一个储存室,奶酪放在那永远不会坏,并 ...
- POJ-2393 Yogurt factory 贪心问题
题目链接:https://cn.vjudge.net/problem/POJ-2393 题意 有一个生产酸奶的工厂,还有一个酸奶放在其中不会坏的储存室 每一单元酸奶存放价格为每周s元,在接下来的N周时 ...
- Yogurt factory(POJ 2393 贪心 or DP)
Yogurt factory Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 8205 Accepted: 4197 De ...
- 【BZOJ】1680: [Usaco2005 Mar]Yogurt factory(贪心)
http://www.lydsy.com/JudgeOnline/problem.php?id=1680 看不懂英文.. 题意是有n天,第i天生产的费用是c[i],要生产y[i]个产品,可以用当天的也 ...
- BZOJ 1740: [Usaco2005 mar]Yogurt factory 奶酪工厂 贪心 + 问题转化
Description The cows have purchased a yogurt factory that makes world-famous Yucky Yogurt. Over the ...
- POJ2393 Yogurt factory 【贪心】
Yogurt factory Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 6821 Accepted: 3488 De ...
- 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#三层架构增删改查中的“查询”问题
序:问题总是反复出现,可能只是一个小小的问题,但是就像肉中刺. 问题: 关于“姓名”字段的拼接问题 姓名字段的拼接:this.Repeater1.DataSource = db.GetList(&qu ...
- Three.js制作一个基本的飞行3D场景【源代码】
原文链接:https://tympanus.net/codrops/2016/04/26/the-aviator-animating-basic-3d-scene-threejs/ 源代码下载链接:h ...
- centos8系统下docker安装jenkins
前提是已经安装好docker 1.下载jenkins(最新版本) docker pull jenkins/jenkins 2.创建用于存放jenkins的文件夹 mkdir /home/var/jen ...
- Redis设计与实现笔记 - hash
基本结构如下 初始状态一直使用 dictht[0],即 0 号哈希表 在发生扩容 rehash的时候,开始渐进式向 dictht[1]哈希表转移, 转移完成后交换 dicth[0] 与 dictht[ ...
- .NET Core项目部署到Linux(Centos7)(五)Centos 7安装.NET Core环境
目录 1.前言 2.环境和软件的准备 3.创建.NET Core API项目 4.VMware Workstation虚拟机及Centos 7安装 5.Centos 7安装.NET Core环境 6. ...
- 微信小程序常用的方法(留着用)
function zero_fill_hex(num, digits) { let s = num.toString(16); while (s.length < digits) s = &qu ...
- linux 配置 python3 CGI
文章更新于:2020-03-04 注1:安装 python 参见: python 的安装使用和基本语法 注2:配置 web 环境参见: Windows&linux使用集成环境搭建 web 服务 ...
- 细数Java项目中用过的配置文件(YAML篇)
灵魂拷问:YAML,在项目中用过没?它与 properties 文件啥区别? 目前 SpringBoot.SpringCloud.Docker 等各大项目.各大组件,在使用过程中几乎都能看到 YAML ...
- Python常见数据结构-Dictionary字典
字典基本特点 字典的每个键值 key=>value 对用冒号 : 分割,每个键值对之间用逗号 , 分割,整个字典包括在花括号 {} 中. 键是唯一的,如果重复最后的一个键值对会替换前面的,值不需 ...
- 15.ASP.NET Core 应用程序中的静态文件中间件
在这篇文章中,我将向大家介绍,如何使用中间件组件来处理静态文件.这篇文章中,我们讨论下面几个问题: 在ASP.NET Core中,我们需要把静态文件存放在哪里? 在ASP.NET Core中 wwwr ...