forked from keshavnandan/Topcoder
-
Notifications
You must be signed in to change notification settings - Fork 0
/
BinPackingEasy.txt
63 lines (33 loc) · 1.2 KB
/
BinPackingEasy.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
PROBLEM STATEMENT
Fox Ciel has some items. The weight of the i-th (0-based) item is item[i]. She wants to put all items into bins.
The capacity of each bin is 300. She can put an arbitrary number of items into a single bin, but the total weight of items in a bin must be less than or equal to 300.
You are given the vector <int> item. It is known that the weight of each item is between 101 and 300, inclusive. Return the minimal number of bins required to store all items.
DEFINITION
Class:BinPackingEasy
Method:minBins
Parameters:vector <int>
Returns:int
Method signature:int minBins(vector <int> item)
CONSTRAINTS
-item will contain between 1 and 50 elements, inclusive.
-Each element of item will be between 101 and 300, inclusive.
EXAMPLES
0)
{150, 150, 150, 150, 150}
Returns: 3
You have five items and each bin can hold at most two of them. You need at least three bins.
1)
{130, 140, 150, 160}
Returns: 2
For example, you can distribute the items in the following way:
Bin 1: 130, 150
Bin 2: 140, 160
2)
{101, 101, 101, 101, 101, 101, 101, 101, 101}
Returns: 5
3)
{101, 200, 101, 101, 101, 101, 200, 101, 200}
Returns: 6
4)
{123, 145, 167, 213, 245, 267, 289, 132, 154, 176, 198}
Returns: 8