Skip to content
Snippets Groups Projects
Commit 89fb0e0a authored by Boubacar's avatar Boubacar
Browse files

solutionFractionnelle

parent 8d48fa47
Branches
No related tags found
2 merge requests!3Dev1,!1solutionFractionnelle
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<project version="4"> <project version="4">
<component name="ProjectRootManager" version="2" languageLevel="JDK_22" default="true" project-jdk-name="22" project-jdk-type="JavaSDK"> <component name="ProjectRootManager" version="2" languageLevel="JDK_23" default="true" project-jdk-name="18" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" /> <output url="file://$PROJECT_DIR$/out" />
</component> </component>
</project> </project>
\ No newline at end of file
No preview for this file type
No preview for this file type
No preview for this file type
...@@ -27,13 +27,16 @@ public class Backpack { ...@@ -27,13 +27,16 @@ public class Backpack {
this.sortByRatio(); this.sortByRatio();
for(Loot loot : loots){ for(Loot loot : loots){
if(loot.getWeight() > this.capacity){ if(sfWeight + loot.getWeight() <= this.capacity){
sfValuee += (loot.getValue() * loot.getWeight()) / (capacity - sfWeight); // Si l'objet entier peut entrer dans le sac
sfWeight += capacity - sfWeight; sfValuee += loot.getValue();
sfWeight += loot.getWeight();
} }
else { else {
sfValuee += loot.getWeight(); // Si l'objet ne peut pas entrer entièrement dans le sac
sfWeight += loot.getWeight(); int remainingWeight = this.capacity - sfWeight;
sfValuee += (int) (loot.getRatio() * remainingWeight);
break;
} }
} }
} }
......
...@@ -5,7 +5,7 @@ public class Loot { ...@@ -5,7 +5,7 @@ public class Loot {
public Loot(int weight, int value) { public Loot(int weight, int value) {
this.weight = weight; this.weight = weight;
this.value = value; this.value = value;
this.ratio = (float) weight/value; this.ratio = (float) value/weight;
} }
public String toString(){ public String toString(){
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment