Un agriculteur indien possède un morceau de terres agricoles, disons L carré kilomètres de long et veut semer le blé ou le riz ou une combinaison des deux. L'agriculteur a une quantité limitée de f kg d'engrais et de p kg d'insecticides. P> Chaque kilomètre carré de blé nécessite F1 kg d'engrais et p1 kg d'insecticide. Chaque kilomètre carré de riziculture nécessite F2 kg d'engrais et p2 kg d'insecticide. Soit S1 être le prix obtenu en vendant du blé récolté à partir d'un kilomètre carré et S2 soit le prix obtenu en vendant de riz récolté à partir d'un kilomètre carré. P> Vous devez trouver le bénéfice total maximum que l'agriculteur peut gagner par Sélection de la zone dans laquelle le blé et / ou le riz doivent être élevés. P> Par exemple: P> l = 10 km2, f = 10 kg, p = 5 kg, f1 = 2 kg, p1 = 2 kg, f2 = 3 kg, p2
= 1 kg, s1 = 14, s2 = 25. p>
BlockQuote> Dans ce cas, l'agriculteur gagnera un bénéfice maximum s'il trouve uniquement du riz sur La seule d'entrée consistera en 9 entiers spatiaux séparés, Format de sortie strong> p> sortie sera p> pour l'exemple considéré dans la sortie de la question sera Disons que L = 10 km2, f = 10 kg, p = 5 kg, F1 = 2 kg, p1 = 2 kg, f2 = 3 kg, p2 = 1 Kg, s1 = 14, s2 = 25. Le bénéfice total sera maximum si l'agriculteur ne plante pas de blé, mais les plantes riz sur 3,33 km2 et une valeur de bénéfices maximale sont de 83,33. P>
3.33 Code> Zone KM2 et la valeur de profit maximum sera
83,33 code>. / p>
L, F, P, F1, P1, F2, P2, s1, s2 code> p>
83,33 0,00 0,00 3,33 code>. p>
p> < p> J'ai besoin d'une solution à ce problème. Cependant, incapable de saisir la déclaration elle-même. S'il vous plaît aidez-moi. P> p>
4 Réponses :
Ceci est un problème d'optimisation linéaire ( https://fr.wikipedia.org/wiki/linear_programmer < / a>) typiquement résolu par l'algorithme simplex ( https://fr.wikipedia.org/wiki/simplex_algorithme ). P>
Si possible, pouvez-vous s'il vous plaît élaborer en ce qui concerne la déclaration de problème indiquée ci-dessus. Merci pour votre réponse.
import java.text.DecimalFormat; import java.util.Scanner; public class Test { public static void main(String args[]) { // String input = "10,10,5,2,2,3,1,14,25"; System.out.println(get_total_profit()); } public static String get_total_profit() { // String[] inputs = input1.split(","); // Piece of farm land in square kilometer Scanner in = new Scanner(System.in); float L = in.nextInt(); // Float.valueOf(inputs[0]); // Fertilizer in kg float F = in.nextInt();// Float.valueOf(inputs[1]); // Insecticide in kg float P = in.nextInt();// Float.valueOf(inputs[2]); // Fertilizer required in kg for square kilometer of Wheat float F1 = in.nextInt();// Float.valueOf(inputs[3]); // Insecticide required in kg for square kilometer of Wheat float P1 = in.nextInt();// Float.valueOf(inputs[4]); // Fertilizer required in kg for square kilometer of Rice float F2 = in.nextInt();// Float.valueOf(inputs[5]); // Insecticide required in kg for square kilometer of Rice float P2 = in.nextInt();// Float.valueOf(inputs[6]); // Selling price of wheat per square kilometer float S1 = in.nextInt();// Float.valueOf(inputs[7]); // Selling price of rice per square kilometer float S2 = in.nextInt();// Float.valueOf(inputs[8]); // Result Variables float totalRiceInsecUsed = 0f; float totalRiceFertUsed = 0f; float totalWheatInsecUsed = 0f; float totalWheatFertUsed = 0f; float areaOfWheat = 0.00f; float areaOfRice = 0.00f; float amount = 0.00f; while (true) { if ((L == areaOfRice + areaOfWheat) || P == totalRiceInsecUsed + totalWheatInsecUsed || F == totalRiceFertUsed + totalWheatFertUsed || F2 == 0 || F1 == 0 || P2 == 0 || P1 == 0) { break; } float calRiceProfit = Math.min(F / F2, P / P2) * S2; float calWheatProfit = Math.min(F / F1, P / P1) * S1; if (calRiceProfit > calWheatProfit) { float areaInsecUsed = P / P2; float areaFertUsed = F / F2; if (areaInsecUsed > areaFertUsed) { L = L - areaFertUsed; F2 = 0; totalRiceFertUsed = totalRiceFertUsed + F2; areaOfRice = areaOfRice + areaFertUsed; amount = amount + areaFertUsed * S2; } else if (areaInsecUsed < areaFertUsed) { L = L - areaInsecUsed; P2 = 0; totalRiceInsecUsed = totalRiceInsecUsed + areaInsecUsed; areaOfRice = areaOfRice + areaInsecUsed; amount = amount + areaInsecUsed * S2; } } else { float areaInsecUsed = P / P1; float areaFertUsed = F / F1; if (areaInsecUsed > areaFertUsed) { L = L - areaFertUsed; F1 = 0; totalWheatFertUsed = totalWheatFertUsed + F1; areaOfWheat = areaOfWheat + areaFertUsed; amount = amount + areaFertUsed * S1; } else if (areaInsecUsed < areaFertUsed) { L = L - areaInsecUsed; P1 = 0; totalWheatInsecUsed = totalWheatInsecUsed + areaInsecUsed; areaOfWheat = areaOfWheat + areaInsecUsed; amount = amount + areaInsecUsed * S1; } } } DecimalFormat df = new DecimalFormat(); df.setMaximumFractionDigits(2); df.setMinimumFractionDigits(2); return df.format(amount) + "," + df.format(areaOfWheat) + "," + df.format(areaOfRice); } }
import java.text.DecimalFormat; import java.util.Scanner; public class CandidateCode { public static void main(String args[]) { System.out.println(get_total_profit()); } public static String get_total_profit() { Scanner in = new Scanner(System.in); float L = in.nextInt(); float F = in.nextInt(); float P = in.nextInt(); float F1 = in.nextInt(); float P1 = in.nextInt(); float F2 = in.nextInt(); float P2 = in.nextInt(); float S1 = in.nextInt(); float S2 = in.nextInt(); float totalRiceInsecUsed = 0f; float totalRiceFertUsed = 0f; float totalWheatInsecUsed = 0f; float totalWheatFertUsed = 0f; float areaOfWheat = 0.00f; float areaOfRice = 0.00f; float amount = 0.00f; while (true) { if ((L == areaOfRice + areaOfWheat) || P == totalRiceInsecUsed + totalWheatInsecUsed || F == totalRiceFertUsed + totalWheatFertUsed || F2 == 0 || F1 == 0 || P2 == 0 || P1 == 0) { break; } float calRiceProfit = Math.min(F / F2, P / P2) * S2; float calWheatProfit = Math.min(F / F1, P / P1) * S1; if (calRiceProfit > calWheatProfit) { float areaInsecUsed = P / P2; float areaFertUsed = F / F2; if (areaInsecUsed > areaFertUsed) { L = L - areaFertUsed; F2 = 0; totalRiceFertUsed = totalRiceFertUsed + F2; areaOfRice = areaOfRice + areaFertUsed; amount = amount + areaFertUsed * S2; } else if (areaInsecUsed < areaFertUsed) { L = L - areaInsecUsed; P2 = 0; totalRiceInsecUsed = totalRiceInsecUsed + areaInsecUsed; areaOfRice = areaOfRice + areaInsecUsed; amount = amount + areaInsecUsed * S2; } } else { float areaInsecUsed = P / P1; float areaFertUsed = F / F1; if (areaInsecUsed > areaFertUsed) { L = L - areaFertUsed; F1 = 0; totalWheatFertUsed = totalWheatFertUsed + F1; areaOfWheat = areaOfWheat + areaFertUsed; amount = amount + areaFertUsed * S1; } else if (areaInsecUsed < areaFertUsed) { L = L - areaInsecUsed; P1 = 0; totalWheatInsecUsed = totalWheatInsecUsed + areaInsecUsed; areaOfWheat = areaOfWheat + areaInsecUsed; amount = amount + areaInsecUsed * S1; } } } DecimalFormat df = new DecimalFormat(); df.setMaximumFractionDigits(2); df.setMinimumFractionDigits(2); return df.format(amount) + " " + df.format(areaOfWheat) + " " + df.format(areaOfRice); } }
Pourriez-vous s'il vous plaît ajouter quelques explications pour votre code et décomposer votre solution?
import java.text.DecimalFormat; import java.util.Scanner; public class CandidateCode { public static void main(String args[]) { // String input = "10,10,5,2,2,3,1,14,25"; System.out.print(get_total_profit()); } public static String get_total_profit() { // String[] inputs = input1.split(","); // Piece of farm land in square kilometer Scanner in = new Scanner(System.in); float L = in.nextInt(); // Float.valueOf(inputs[0]); // Fertilizer in kg float F = in.nextInt();// Float.valueOf(inputs[1]); // Insecticide in kg float P = in.nextInt();// Float.valueOf(inputs[2]); // Fertilizer required in kg for square kilometer of Wheat float F1 = in.nextInt();// Float.valueOf(inputs[3]); // Insecticide required in kg for square kilometer of Wheat float P1 = in.nextInt();// Float.valueOf(inputs[4]); // Fertilizer required in kg for square kilometer of Rice float F2 = in.nextInt();// Float.valueOf(inputs[5]); // Insecticide required in kg for square kilometer of Rice float P2 = in.nextInt();// Float.valueOf(inputs[6]); // Selling price of wheat per square kilometer float S1 = in.nextInt();// Float.valueOf(inputs[7]); // Selling price of rice per square kilometer float S2 = in.nextInt();// Float.valueOf(inputs[8]); // Result Variables float totalRiceInsecUsed = 0f; float totalRiceFertUsed = 0f; float totalWheatInsecUsed = 0f; float totalWheatFertUsed = 0f; float areaOfWheat = 0.00f; float areaOfRice = 0.00f; float amount = 0.00f; while (true) { if ((L == areaOfRice + areaOfWheat) || P == totalRiceInsecUsed + totalWheatInsecUsed || F == totalRiceFertUsed + totalWheatFertUsed || F2 == 0 || F1 == 0 || P2 == 0 || P1 == 0) { break; } float calRiceProfit = Math.min(F / F2, P / P2) * S2; float calWheatProfit = Math.min(F / F1, P / P1) * S1; if (calRiceProfit > calWheatProfit) { float areaInsecUsed = P / P2; float areaFertUsed = F / F2; if (areaInsecUsed > areaFertUsed) { L = L - areaFertUsed; F2 = 0; totalRiceFertUsed = totalRiceFertUsed + F2; areaOfRice = areaOfRice + areaFertUsed; amount = amount + areaFertUsed * S2; } else if (areaInsecUsed < areaFertUsed) { L = L - areaInsecUsed; P2 = 0; totalRiceInsecUsed = totalRiceInsecUsed + areaInsecUsed; areaOfRice = areaOfRice + areaInsecUsed; amount = amount + areaInsecUsed * S2; } } else { float areaInsecUsed = P / P1; float areaFertUsed = F / F1; if (areaInsecUsed > areaFertUsed) { L = L - areaFertUsed; F1 = 0; totalWheatFertUsed = totalWheatFertUsed + F1; areaOfWheat = areaOfWheat + areaFertUsed; amount = amount + areaFertUsed * S1; } else if (areaInsecUsed < areaFertUsed) { L = L - areaInsecUsed; P1 = 0; totalWheatInsecUsed = totalWheatInsecUsed + areaInsecUsed; areaOfWheat = areaOfWheat + areaInsecUsed; amount = amount + areaInsecUsed * S1; } } } DecimalFormat df = new DecimalFormat(); df.setMaximumFractionDigits(2); df.setMinimumFractionDigits(2); return df.format(amount) + " " + df.format(areaOfWheat) + " " + df.format(areaOfRice); } }
Quelle partie de la déclaration n'est-elle pas capable de saisir? En outre, inclure votre tentative, décrivant où vous êtes coincé
Semble à un travail de travail et je ne vois aucun code, vous n'avez pas spécifié le langage de programmation que vous avez utilisé.
@Francesco c'est java