Make Solution Continuous
This commit is contained in:
parent
c9d5a7a84c
commit
8a95eb668b
|
|
@ -1,4 +1,6 @@
|
|||
#include "backpack.h"
|
||||
#include <algorithm>
|
||||
#include <cmath>
|
||||
|
||||
/* Optimized insertion sort algorithm utilizing the Item's getRatio() function
|
||||
*/
|
||||
|
|
@ -50,6 +52,15 @@ void Backpack::greedyPack() {
|
|||
<< this->availableItems[i].weight << "\t"
|
||||
<< this->availableItems[i].value
|
||||
<< "\t Factor: 1.00\n"; // output
|
||||
} else {
|
||||
float factor = (float)(this->maxWeight - this->currentWeight) /
|
||||
this->availableItems[i].weight;
|
||||
factor = std::round(factor * 100) / 100;
|
||||
std::cout << "\t" << this->availableItems[i].name << ":\t"
|
||||
<< this->availableItems[i].weight << "\t"
|
||||
<< this->availableItems[i].value << "\t Factor: " << factor
|
||||
<< std::endl;
|
||||
break;
|
||||
}
|
||||
if ((this->currentWeight - this->maxWeight) ==
|
||||
0) { // if the backpack is completely full, the loop can be exited -
|
||||
|
|
|
|||
Loading…
Reference in New Issue