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

solutionFractionnelle

parent 8d48fa47
No related branches found
No related tags found
2 merge requests!3Dev1,!1solutionFractionnelle
<?xml version="1.0" encoding="UTF-8"?>
<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" />
</component>
</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 {
this.sortByRatio();
for(Loot loot : loots){
if(loot.getWeight() > this.capacity){
sfValuee += (loot.getValue() * loot.getWeight()) / (capacity - sfWeight);
sfWeight += capacity - sfWeight;
if(sfWeight + loot.getWeight() <= this.capacity){
// Si l'objet entier peut entrer dans le sac
sfValuee += loot.getValue();
sfWeight += loot.getWeight();
}
else {
sfValuee += loot.getWeight();
sfWeight += loot.getWeight();
// Si l'objet ne peut pas entrer entièrement dans le sac
int remainingWeight = this.capacity - sfWeight;
sfValuee += (int) (loot.getRatio() * remainingWeight);
break;
}
}
}
......
......@@ -5,7 +5,7 @@ public class Loot {
public Loot(int weight, int value) {
this.weight = weight;
this.value = value;
this.ratio = (float) weight/value;
this.ratio = (float) value/weight;
}
public String toString(){
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment