C - Yogurt factory
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) cents to produce one unit of 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
Line 1: Two space-separated integers, N and S.
Lines 2..N+1: Line i+1 contains two space-separated integers: C_i and Y_i.
Output
- Line 1: Line 1 contains a single integer: the minimum total cost to satisfy the yogurt schedule. Note that the total might be too large for a 32-bit integer.
Sample Input
4 5
88 200
89 400
97 300
91 500
Sample Output
126900
Hint
OUTPUT DETAILS:
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.
这应该算贪心的思想吧,刚做不清楚;
就是从这周开始,要不要把接下来几天的也生产掉,对比一下花费就可以了
#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include<cmath>
#include<string.h>
#include<algorithm>
#define sf scanf
#define pf printf
#define pb push_back
#define mm(a,b) memset((a),(b),sizeof(a))
#include<vector>
const double pi=acos(-1.0);
typedef __int64 ll;
typedef long double ld;
const ll MOD=1e9+7;
using namespace std;
int num[10005],n,s,cost[10005],d[10005];
int main()
{
mm(num,0);
mm(cost,0);
mm(d,0);
cin>>n>>s;
for(int i=0;i<n;i++)
sf("%d%d",&cost[i],&num[i]);
for(int i=0;i<n;i++)
{
int ans=0;
for(int j=1;j<n-i;j++)
{
if(cost[i]*num[i+j]+num[i+j]*j*s<cost[i+j]*num[i+j])
{
ans++;
}else
break;
}
if(ans)
{
for(int j=0;j<=ans;j++)
{
d[i]+=num[i+j];
}
i+=ans;
}else
d[i]=num[i];
}
ll sum=0,tot=0;
for(int i=0;i<n;i++)
{
sum+=d[i]*cost[i]+tot*s;
tot=tot+d[i]-num[i];
}
pf("%I64d",sum);
return 0;
}
C - Yogurt factory的更多相关文章
- poj 2393 Yogurt factory
http://poj.org/problem?id=2393 Yogurt factory Time Limit: 1000MS Memory Limit: 65536K Total Submis ...
- BZOJ1680: [Usaco2005 Mar]Yogurt factory
1680: [Usaco2005 Mar]Yogurt factory Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 106 Solved: 74[Su ...
- Yogurt factory(POJ 2393 贪心 or DP)
Yogurt factory Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 8205 Accepted: 4197 De ...
- 1740: [Usaco2005 mar]Yogurt factory 奶酪工厂
1740: [Usaco2005 mar]Yogurt factory 奶酪工厂 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 119 Solved: ...
- POJ 2393 Yogurt factory 贪心
Description The cows have purchased a yogurt factory that makes world-famous Yucky Yogurt. Over the ...
- Yogurt factory
Description The cows have purchased a yogurt factory that makes world-famous Yucky Yogurt. Over the ...
- 【BZOJ】1680: [Usaco2005 Mar]Yogurt factory(贪心)
http://www.lydsy.com/JudgeOnline/problem.php?id=1680 看不懂英文.. 题意是有n天,第i天生产的费用是c[i],要生产y[i]个产品,可以用当天的也 ...
- POJ2393 Yogurt factory 【贪心】
Yogurt factory Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 6821 Accepted: 3488 De ...
- BZOJ 1740: [Usaco2005 mar]Yogurt factory 奶酪工厂 贪心 + 问题转化
Description The cows have purchased a yogurt factory that makes world-famous Yucky Yogurt. Over the ...
随机推荐
- OUI启动时的小错误PRVF-0002
[oracle@bys3 database]$ Starting Oracle Universal Installer... Checking Temp space: must be greater ...
- IOS Using UIAlertView to show alerts
UIAlertView in other words, it's a dialog box. You want to show a message or ask user to confirm an ...
- web打印控件Lodop轻松输出清晰的图表和条码
一.仅用两行语句实现极其复杂的图表打印.类似如下两句: LODOP.ADD_PRINT_CHART(0,0,400,400,5,document.getElementByI d('table001') ...
- iOS 一些常见问题的整理
一.通知 对于通知,大家想必都不陌生,它是一个单例,允许当事件发生时通知一些对象,让我们在低程度耦合的情况下,来达到通信的目的. 通知的优势:1.不需要编写太多代码,实现比较简单2.对于一个发出的通知 ...
- 二值化函数cvThreshold()参数CV_THRESH_OTSU的疑惑【转】
查看OpenCV文档cvThreshold(),在二值化函数cvThreshold(const CvArr* src, CvArr* dst, double threshold, double max ...
- 升级python(linux)
查看系统当前python版本 2: [root@wangyuelou ~]# python Python 2.4.3 (#1, May 5 2011, 16:39:10) [GCC ...
- Socket网络编程--网络爬虫(4)
上一小节我们已经实现了获取博客园最近博客的200页里面的用户名,并保存在一个map中.一开始是想通过这个用户名然后构造一个博客地址.然后在这个地址中查找心得用户名,但是后来发现这个的效率不是很高,虽然 ...
- Selenium Web 自动化 - Selenium常用API
Selenium Web 自动化 - Selenium常用API 2016-08-01 目录 1 对浏览器操作 1.1 用webdriver打开一个浏览器 1.2 最大化浏览器&关闭浏览器 ...
- bootstrap 3.0 LESS源代码浅析(二)
border-radius是最常见的CSS3属性,但你知道他多少东西呢? 比如: border-radius:2em; 相当于什么? border-top-left-radius:2em; borde ...
- android平台的三个编译命令——make,mm,mmm
在Android源码根目录下,执行以下三步即可编译android: 1. build/envsetup.sh #这个脚本用来设置android的编译环境; 2. lunch #选择编译目标 3 ...