POJ2393 Yogurt factory 【贪心】
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 6821 | Accepted: 3488 |
Description
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
* 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.
Source
每次更新相邻的下一周就可以。由于若下一周被更新,那么下一周能够用来更新剩下的周,所以当前周仅仅须要负责下一周。
#include <stdio.h>
#include <string.h> #define maxn 10002 int min(int a, int b) {
return a < b ? a : b;
} int X[maxn], Y[maxn]; int main() {
int N, S, i, j;
__int64 sum;
while(scanf("%d%d", &N, &S) == 2) {
for(i = 0; i < N; ++i)
scanf("%d%d", &X[i], &Y[i]);
for(i = sum = 0; i < N; ++i) {
sum += X[i] * Y[i];
if(i != N - 1)
X[i+1] = min(X[i+1], X[i] + S);
}
printf("%I64d\n", sum);
}
return 0;
}
2014-12-1更新
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <queue>
using namespace std;
typedef long long LL; LL ans; int main() {
int N, S, i, c, m, pre;
scanf("%d%d", &N, &S);
scanf("%d%d", &c, &m);
pre = c + S; // 仓库价格
ans += c * m;
while(--N) {
scanf("%d%d", &c, &m);
if(pre < c) c = pre;
else pre = c;
ans += c * m;
pre += S;
}
printf("%lld\n", ans);
return 0;
}
POJ2393 Yogurt factory 【贪心】的更多相关文章
- 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周时 ...
- POJ 2393 Yogurt factory 贪心
Description The cows have purchased a yogurt factory that makes world-famous Yucky Yogurt. Over the ...
- poj_2393 Yogurt factory 贪心
Yogurt factory Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 16669 Accepted: 8176 D ...
- 百炼 POJ2393:Yogurt factory【把存储费用用递推的方式表达】
2393:Yogurt factory 总时间限制: 1000ms 内存限制: 65536kB 描述 The cows have purchased a yogurt factory that m ...
- poj2393 Yogurt factory(贪心,思考)
https://vjudge.net/problem/POJ-2393 因为仓储费是不变的. 对于每一周,要么用当周生产的,要么接着上一周使用的价格(不一定是输入的)加上固定的仓储费用. 应该算是用到 ...
- poj2393 Yogurt factory
思路: 贪心. 实现: #include <iostream> #include <cstdio> #include <algorithm> using names ...
- 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]个产品,可以用当天的也 ...
随机推荐
- nginx--提供一键安装脚本
nginx特点 基于进程池实现的fastcgi 单一进程即可实现处理上千的连接 易于扩展的插件系统 安装篇 *下载源码 curl -O http://nginx.org/download/nginx- ...
- swift 工作日志
开发问题汇总: tableview.register(CEImpWalletHomeCell.self, forCellReuseIdentifier: "cell") var c ...
- 使用vs2010打开vs2015的项目
本来在单位项目一直使用vs2010写,五一放假拿回家 ,用vs2015捣鼓了一下 当然向下兼容打开毫无问题,结果回来悲催了,用vs2010打不开了 ,打不开. 记得以前有个转换向导,可是这次没看见,一 ...
- 如何在linux使用nmap端口扫描工具扫描网段内开放的端口
在另一个linux主机上,使用nmap命令即可 ,比如 我在1.1.1.2上开放了端口1111 -A -j ACCEPT 在1.1.1.1上执行 即可查到
- Apache Maven 3.0.3 (yum) 安裝 (CentOS 6.4 x64)
介紹http://maven.apache.org/ Maven是一個專案的開發,管理和綜合工具. 下載http://maven.apache.org/download.cgi 參考http://ma ...
- 百度地图API获取数据
目前,大厂的服务范围越来越广,提供的数据信息也是比较全的,在生活服务,办公领域,人工智能等方面都全面覆盖,相对来说,他们的用户基数大,通过用户获取的信息也是巨大的.除了百度提供api,国内提供免费AP ...
- bazel和TensorFlow安装
bazel安装:https://docs.bazel.build/versions/master/install-ubuntu.html#install-with-installer-ubuntu 安 ...
- 小程序接口越过域名和https限制方法
都知道小程序上线接口需要域名,还需要https,就算是体验版的都是需要的,这样就筛选掉一大批开发者,像我这样只有学生轻量级服务器的学生要开发自己的小程序就很为难,但今天确惊奇的在小程序社区里面找到了用 ...
- NOIP2000方格取数(洛谷,动态规划递推)
先上题目: P1004 方格取数 下面上ac代码: ///如果先走第一个再走第二个不可控因素太多 #include<bits/stdc++.h> #define ll long long ...
- 洛谷——P1176 路径计数2
P1176 路径计数2 题目描述 一个N \times NN×N的网格,你一开始在(1,1)(1,1),即左上角.每次只能移动到下方相邻的格子或者右方相邻的格子,问到达(N,N)(N,N),即右下角有 ...