-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFirstFitBinPacking.cpp
More file actions
40 lines (33 loc) · 917 Bytes
/
Copy pathFirstFitBinPacking.cpp
File metadata and controls
40 lines (33 loc) · 917 Bytes
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
#include<bits/stdc++.h>
using namespace std;
#define MAX_GROUPS 100
#define MAX_BUSES 100
#define BUS_CAPACITY 7
int main() {
int n;
cout <<"Enter the number of groups: ";
cin >>n;
int groupsize[MAX_GROUPS];
cout <<"Enter the size of each group: ";
for(int i=0; i<n; i++) {
cin >>groupsize[i];
}
int bus_seat[MAX_BUSES]= {0};
int busCount= 0;
for(int i=0; i<n; i++) {
int placed= 0; //grp is not seated
for(int j=0; j<busCount; j++) {
if(bus_seat[j]+groupsize[i] <= BUS_CAPACITY) {
bus_seat[j] += groupsize[i]; //numb i people will seat in bus j
placed =1; //grp is seated
break;
}
}
if(!placed) {
bus_seat[busCount]= groupsize[i];
busCount++;
}
}
cout <<"Minimum number of mini bus: "<<busCount<<"\n";
return 0;
}