题目描述:

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

-----------------------
这道题是我在HURBST做的题目,链接是https://vjudge.net/contest/262212#problem/D 中文理解:有一个酸奶酪生产商,每一个星期都有其需求量和价格量,奶酪可以保存到下个星期使用,不过有保存费用,此题目要求你找出最小费用的解; 个人看法:这道题目是贪心的基础题目,它满足了贪心算法的基于当前是最优解,找出下一个最优解,保证这一步是最优解。
 #include<stdio.h>
#include<algorithm>
#include<math.h>
#include<vector>
#include<iterator>
#include<string>
#include<string.h>
#include<ctype.h>
#include<map>
#include<stack>
#include<queue>
#include<iostream>
#include<time.h> using namespace std; #define rep(i ,a, b) for(int i = a; i <= b; i++)
#define per(i, a, b) for(int i = a; i <= b; i--)
typedef long long ll;//数据量大,用longlong来进行运算较合适。不然会数据溢出。 struct milk
{
ll c_i, y_i, id;
}a[]; ll findmin(ll n, ll s)
{
ll ans=a[].c_i*a[].y_i, k = ;
for(ll i = ; i < n; i++)
{
ll temp = a[k].c_i+s*(i- a[k].id), cur = a[i].c_i;//记录前一周牛奶的价格和这个一周的价格,进行比较然后,选取较小的作为当前的最小解;
if(temp < cur)
{
ans += temp*a[i].y_i;
}
else
{
ans += cur*a[i].y_i;
k = i;
}
}
return ans;
} int main()//这是贪心问题。
{
ll n, s;
while(scanf("%lld%lld", &n, &s) != EOF)
{
for(ll i =; i < n; i++)
{
scanf("%lld%lld", &a[i].c_i, &a[i].y_i);
a[i].id = i;
}
printf("%lld\n", findmin(n, s));
}
return ;
}

 

贪心算法HURUST题目的更多相关文章

  1. 1033. To Fill or Not to Fill (25) -贪心算法

    题目如下: With highways available, driving a car from Hangzhou to any other city is easy. But since the ...

  2. 【九度OJ】题目1434贪心算法

    题目 本题的贪心算法策略需要深入思考一下 看到题目,最初没有理解题目的要求:看尽量多的完整的节目.尽量多是指数量多,自己理解成观看的时间最长.这样想其实简化了这道题. 正确理解题意后,首先想到的想法是 ...

  3. Leetcode题目55.跳跃游戏(贪心算法-中等)

    题目描述: 给定一个非负整数数组,你最初位于数组的第一个位置. 数组中的每个元素代表你在该位置可以跳跃的最大长度. 判断你是否能够到达最后一个位置. 示例 1: 输入: [2,3,1,1,4] 输出: ...

  4. 题目1437:To Fill or Not to Fill:贪心算法解决加油站选择问题(未解决)

    //贪心算法解决加油站选择问题 //# include<iostream> # include<stdio.h> using namespace std; # include& ...

  5. 贪心算法(Greedy Algorithm)

    参考: 五大常用算法之三:贪心算法 算法系列:贪心算法 贪心算法详解 从零开始学贪心算法 一.基本概念: 所谓贪心算法是指,在对问题求解时,总是做出在当前看来是最好的选择.也就是说,不从整体最优上加以 ...

  6. poj 1088 滑雪(贪心算法)

    思想: (贪心算法 ,看到题目是中文才做的) 先对数组中的数据进行排序,从最小的数据计算 当前的顶点的可以滑行的最大值=max(周围可达的顶点的可以滑行的最大值)+1 这样计算最后产生的路径肯定是最大 ...

  7. 剑指Offer——贪心算法

    剑指Offer--贪心算法 一.基本概念 所谓贪心算法是指,在对问题求解时,总是做出在当前看来是最好的选择.也就是说,不从整体最优上加以考虑,他所做出的仅是在某种意义上的局部最优解.虽然贪心算法不能对 ...

  8. 贪心算法----区间选点问题(POJ1201)

    题目: 题目的大致意思是,给定n个闭区间,并且这个闭区间上的点都是整数,现在要求你使用最少的点来覆盖这些区间并且每个区间的覆盖的点的数量满足输入的要求点覆盖区间的数量. 输入: 第一行输入n,代表n个 ...

  9. python数据结构与算法第十六天【贪心算法与动态规划】

    对于一个字符串,对字符串进行分割,分割后的每个子字符串都为回文串,求解所有可行的方案 这个问题可以使用贪心算法与动态规划来求解 步骤如下: (1)先得出所有的单个字符的回文串,单个字符必定是回文串, ...

随机推荐

  1. Python编写API接口

    要求通过http://192.168.50.74/aptest/calc/?a=aa&c=00&b=bb进行访问,参数a="aa",b="bb" ...

  2. mySQL 约束 (Constraints)

    约束用于限制加入表的数据的类型: 1.创建表时规定约束(通过 CREATE TABLE 语句) 2.表创建之后也可以(通过 ALTER TABLE 语句). 约束类型: NOT NULL(非空) UN ...

  3. 第 14 章 结构和其他数据形式(伸缩型数组成员C99)

    伸缩型数组成员C99 声明一个伸缩型数组成员的规则: 1.伸缩型数组成员必须是结构的最后一个成员: 2.结构中必须至少有一个成员: 3.伸缩数组的方括号是空的. 示例 struct flex { in ...

  4. ubuntu各类问题笔记

    ubuntu文本编辑器中文中文乱码问题解决 转载自:http://www.2cto.com/os/201201/117535.html 缺省配置下,用Ubuntu 的文本编辑器(gedit)打开GB1 ...

  5. 详解Web请求中的DNS域名解析

    当我们打开浏览器,输入一个URL去请求我们需要的资源,但是URL是需要解析成对应的IP地址才能与远程主机建立连接,如何将URL解析成IP就是DNS的工作范畴,即使作为开发人员,这个过程我们也感觉不到, ...

  6. Atcoder 水题选做

    为什么是水题选做呢?因为我只会水题啊 ( 为什么是$Atcoder$呢?因为暑假学长来讲课的时候讲了三件事:不要用洛谷,不要用dev-c++,不要用单步调试.$bzoj$太难了,$Topcoder$整 ...

  7. top,ps查看进程使用内存情况

    ps -e -o 'pid,comm,args,pcpu,vsz,stime,user,uid' |grep chrome|grep -v grepwatch 'ps -e -o 'pid,comm, ...

  8. [转]用多线程方法实现在MFC/WIN32中调用OpenGL函数并创建OpenGL窗口

    原文链接: 1.用多线程方法实现在MFC/WIN32中调用OpenGL函数并创建OpenGL窗口 2.Windows MFC 两个OpenGL窗口显示与线程RC问题

  9. 十分钟教你使用NoteExpress

    http://www.a-site.cn/article/761794.html 如果你正走在读研的路上,不管是什么专业,日常生活中都少不了读文献.读文献和读文献. 与其等到文献堆积如山,给阅读和使用 ...

  10. liMarquee – jQuery无缝滚动插件(制作跑马灯效果)

    liMarquee 是一款基于 jQuery 的无缝滚动插件,类似于 HTML 的 marquee 标签,但比 marquee 更强大.它可以应用于任何 Web 元素,包括文字.图像.表格.表单等元素 ...