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: ...
随机推荐
- python:爬取博主的所有文章的链接、标题和内容
以爬取我自己的博客为例:https://www.cnblogs.com/Mr-choa/ 1.获取所有的文章的链接: 博客文章总共占两页,比如打开第一页:https://www.cnblogs.com ...
- Linux 压缩备分篇(一 备份数据)
备份文件 dump dump: -S 仅列出待备份数据需要多少磁盘空间才能够备份完毕 -u 将 ...
- ensp的基础路由命令,接口,下一跳的配置,入门必备
关于ensp入门事情,第一件事当是安装必备三件套:而后,应该是接触路由和PC机了,最烦人满屏代码,眼花缭乱: 今天写一篇零基础接触ensp的首次操作,PC-路由-路由-PC的互通实验: 实验要拉出两台 ...
- Array(数组)对象-->sort() 方法
1.定义和用法 sort() 方法用于对数组的元素进行排序. 默认排序顺序为按字母升序. 语法: array.sort(sortfunction) 参数: sortfunction:规定排序顺序.必须 ...
- django 利用ORM对单表进行增删改查
牛小妹上周末,一直在尝试如何把数据库的数据弄到界面上.毕竟是新手,搞不出来,文档也看不懂.不过没关系,才刚上大学.今晚我们就来解释下,要把数据搞到界面的第一步.先把数据放到库里,然后再把数据从库里拿出 ...
- hadoop(八)集群namenode启动ssh免密登录(完全分布式五)|10
前置章节:hadoop集群配置同步(hadoop完全分布式四)|10 启动namenode之前: 1. 先查看有无节点启动,执行jps查看,有的话停掉 [shaozhiqi@hadoop102 ~]$ ...
- golang环境安装和配置
go中环境安装 前言 最近在工作中需要新配置go环境,每次都要去网上查找教程,浪费时间,那么就自己总结下. 下载安装 linuxGolang官网下载地址:https://golang.org/dl/1 ...
- 通过Java HTTP连接将网络图片下载到本地
通过Java HTTP连接将网络图片下载到本地 只知道浏览器使用的是HTTP协议,那么如何将网络资源使用JavaHTTP下载下来呢! 这只是一个非常简单的小示例,只是不想每次碰到关于此方面的内容忘 ...
- C#多线程(4):进程同步Mutex类
Mutex 类 构造函数和方法 系统只能运行一个程序的实例 解释一下上面的示例 接替运行 进程同步示例 另外 Mutex 类 Mutex 中文为互斥,Mutex 类叫做互斥锁.它还可用于进程间同步的同 ...
- 【图解】你还在为 TCP 重传、滑动窗口、流量控制、拥塞控制发愁吗?看完图解就不愁了
每日一句英语学习,每天进步一点点: 前言 前一篇「硬不硬你说了算!近 40 张图解被问千百遍的 TCP 三次握手和四次挥手面试题」得到了很多读者的认可,在此特别感谢你们的认可,大家都暖暖的. 来了,今 ...