题目描述:

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. 转:Sql Server中的表访问方式Table Scan, Index Scan, Index Seek

    0.参考文献 Table Scan, Index Scan, Index Seek SQL SERVER – Index Seek vs. Index Scan – Diffefence and Us ...

  2. Python中的分组函数(groupby、itertools)

    from operator import itemgetter #itemgetter用来去dict中的key,省去了使用lambda函数 from itertools import groupby ...

  3. unbuntu 安装python包提示E: Unable to locate package python-timeout

    今天本想着在unbuntu环境下安装python的一个包,安装了几次都提示 E: Unable to locate package python-timeout 查阅了一些信息才知道,原来是一些软件源 ...

  4. 极限编程核心价值:沟通(Communication)

    原文:https://deviq.com/communication 极限编程核心价值:简单(Simplicity) 极限编程核心价值:沟通(Communication) 极限编程核心价值:反馈(Fe ...

  5. FastDFS分布式文件系统设计原理

    转载自http://blog.chinaunix.net/uid-20196318-id-4058561.html FastDFS是一个开源的轻量级分布式文件系统,由跟踪服务器(tracker ser ...

  6. sublime出现 unable download.......

    I managed to fix this by changing my package settings. I made my osx downloader preference curl, and ...

  7. nginx静态文件缓存的解决方案

    nginx的一大功能就是完成静态资源的分离部署,减轻后端服务器的压力,如果给这些静态资源再加一级nginx的缓存,可以进一步提升访问效率. 第一步:添加nginx.conf的http级别的缓存配置 # ...

  8. 1、pyspider安装

    系统环境: centos6.6.python2.7 经测试,python2.6安装的pyspider会导致webui无法正常访问 参考博文: http://cuiqingcai.com/2443.ht ...

  9. leetcode322—Coin Change

    You are given coins of different denominations and a total amount of money amount. Write a function ...

  10. JAVA框架 Spring AOP注解

    一.准备工作: 1)导入jar包: 4个jar包. 2)约束:(spring需要所有的约束)有IOC约束和AOP 还有事务(tx)以及注解注入的约束(context). <?xml versio ...