贪心算法
2021-01-22 19:15
标签:algorithm const case cst lines home rom with color 总是做出当前做好的选择。 贪心策略:将问题分成多个子问题;子问题求局部最优解;局部最优解组合成原问题的解。 题目描述 4 2 2.286 有一组 1 维的物品需要打包进一批同样的箱子中。所有的箱子有完全一样的长度 l 以及每一个物品长度 li
(1) 每个箱子最多包含两个物品 你的任务是,给定 n 个整数,l,l1,l2….ln, 计算最小的箱子总数 q. 第一行包含一个数字 n(1
输出一个整数,表示能够包含所有物品的最小的箱子总数。 The sample instance and an optimal solution is shown in the figure below. Items are numbered from 1 to 10 according to the input order. 思考:如果每次选择两个最大的,可能一次性溢出;如果每次挑选两个最小的,可能后面又会溢出,选择的是最大的和最小的,如果首次他们都未通过 贪心算法 标签:algorithm const case cst lines home rom with color 原文地址:https://www.cnblogs.com/juanzhi/p/12886602.html贪心策略
分类:简单贪心 区间贪心咖啡豆问题
FatMouse prepared M pounds of cat food, ready to trade with the cats guarding the warehouse containing his favorite food, JavaBean.
The warehouse has N rooms. The i-th room contains J[i] pounds of JavaBeans and requires F[i] pounds of cat food. FatMouse does not have to trade for all the JavaBeans in the room, instead, he may get J[i]* a% pounds of JavaBeans if he pays F[i]* a% pounds of cat food. Here a is a real number. Now he is assigning this homework to you: tell him the maximum amount of JavaBeans he can obtain.
输入
The input consists of multiple test cases. Each test case begins with a line containing two non-negative integers M and N. Then N lines follow, each contains two non-negative integers J[i] and F[i] respectively. The last test case is followed by two -1’s. All integers are not greater than 1000.
输出
For each test case, print in a single line a real number accurate up to 3 decimal places, which is the maximum amount of JavaBeans that FatMouse can obtain.
样例输入
4 7
1 3
5 5
4 8
3 8
1 2
2 5
2 4
-1 -1
1
2
3
4
5
6
7
8
9
10
样例输出
2.500#include
背包问题
(2) 每个物品要被包含在 q 个箱子中的一个中
(3) 在箱子中物品的总长度不能超过 l输入格式
输出格式
提示 :