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 ...
随机推荐
- 【前端】Sublime text3 插件HTML/CSS/JS prettify 格式化代码
1.首先安装插件 菜单的preference->packages control,然后输入install .. 回车,再输入HTML/CSS/JS prettify 再回车,重启后就可以了. 2 ...
- 【深入】java 单例模式(转)
[深入]java 单例模式 关于单例模式的文章,其实网上早就已经泛滥了.但一个小小的单例,里面却是有着许多的变化.网上的文章大多也是提到了其中的一个或几个点,很少有比较全面且脉络清晰的文章,于是,我便 ...
- Openjudge 8782 乘积最大
伤心,感冒了根本没精力肝题,只能做点小的 描述 今年是国际数学联盟确定的“2000——世界数学年”,又恰逢我国著名数学家华罗庚先生诞辰90周年.在华罗庚先生的家乡江苏金坛,组织了一场别开生面的数学智力 ...
- 新建的 web 工程 有红色的惊叹号
新建的 web 工程 有红色的感叹号问题: 在eclipse 中新建一个web工程,但是工程上有红色的感叹号.解决: 1.右键工程,选择Build Path-->Configur ...
- html转jsp乱码问题
先由html后缀转为jsp后缀.然后添加 <%@ page language="java" import="java.util.*" pageEncodi ...
- jquery ajax 应用返回类型是html json
jquery ajax 例子: function JudgeUserName() { $.ajax({ type:"GET&q ...
- Codeforce#331 (Div. 2) A. Wilbur and Swimming Pool(谨以此题来纪念我的愚蠢)
C time limit per test 1 second memory limit per test 256 megabytes input standard input output stand ...
- mq安装参考
CentOS 6.2 64bit 安装erlang及RabbitMQ Server 1.操作系统环境(CentOS 6.2 64bit) [root@leekwen ~]# cat /etc/issu ...
- Logistic Regression and Gradient Descent
Logistic Regression and Gradient Descent Logistic regression is an excellent tool to know for classi ...
- JS Resizable Panel 练习
Resizable Panel HTML <!doctype html> <html> <head> <title>Resizable Panel< ...