这是问题陈述
一位印度农民有一片农田,比如说1平方公里长,他想种小麦或水稻,或者两者兼有。农民有有限的F公斤肥料和P公斤杀虫剂。
每平方公里的小麦需要F1公斤化肥和P1公斤杀虫剂。每平方公里的水稻种植需要F2公斤化肥和P2公斤杀虫剂。假设S1是出售从一平方公里收获的小麦获得的价格,S2是出售从一平方公里收获的水稻获得的价格。
你必须通过选择种植小麦和/或水稻的地区来找到农民可以获得的最大总利润。
例如:
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。
在这种情况下,如果农民只在3.33平方公里的面积上播种水稻,将获得最大利润,最大利润值将为83.33。
输入格式
唯一的输入将由9个分隔的整数组成,L、F、P、F1、P1、F2、P2、S1、S2
约束条件
1 <= L <= 10^4
1 <= F <= 10^4
1 <= P <= 10^4
F1 + F2< = F
P1 + P2 <= P
1 <= S1 <= 10^4
1 <= S2 <= 10^4
输出格式
输出将为
最大利润更正最多2位数字
- 以km 2为单位的值,小麦应种植正确,最多2位数
- 以公里2为单位的值,应种植水稻,最多为2位数。
例如,问题中考虑的示例输出为83.33 0.00 3.33。
样本测试用例
输入
10 10 5 2 2 3 1 14 25
输出
83.33 0.00 3.33
解释
假设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。如果农民在3.33 km2的面积上不种植任何小麦而种植水稻,则总利润最大,最大利润值为83.33。
我需要解决这个问题。但是,无法掌握陈述本身。请帮助我。
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[]) {
// 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);
}
}
这是一个线性最佳化问题(https://en.wikipedia.org/wiki/Linear_programming),通常由单纯形算法(https://en.wikipedia.org/wiki/Simplex_algorithm)解决。
我在用gcc和clang做实验,看看它们是否可以优化 以返回中间常量。 事实证明,他们可以: 但是令人惊讶的是,移除静态输出会产生相同的汇编输出。这让我很好奇,因为如果全局变量不是< code>static,它应该是可插值的,用中间变量替换引用应该可以防止全局变量的插值。 的确如此: 产出 编译器可以用中间变量替换外部全局变量的引用吗?这些不也应该被干预吗? 编辑: Gcc 不会优化外部函数调用(
排麦组件的核心类是CCBarLeyManager,获取核心类的实例:CCBarLeyManager mBarLeyManager = CCBarLeyManager.getInstance(); 1.1 举手连麦 学生可点击连麦申请连麦,需老师确认才可连麦 老师可以邀请学生连麦,需学生同意才可连麦 学生可以点击下麦,老师也可以踢学生下麦 1.2 自由连麦 学生可自由连麦,无需老师确认 学生可以点击
日期: 2019-11-19 创盛视联数码科技(北京)有限公司 聊天组件的核心类是CCBarleyManager; //在工程需要的地方引入头文件 #import <CCBarleyLibrary/CCBarleyLibrary.h> //1、类的实例化 + (instancetype)sharedBarley; //2、与BaseSDK建立联系 - (void)addBasicClient:
1.1 组件引入 需使用特定场景连麦模式,可在线引用排麦插件 <script src="https://class.csslcloud.net/static/dist/js/classMode.js"></script> 1.2 排麦插件包含功能 功能 描述 多中连麦模式支持 自定义多种连麦场景(自由、举手、自动) 2.1 举手连麦 学生可举手申请连麦,需老师确认才可连麦 老师可以邀请学生连麦
本文档提供的技术与工具概述,有助于使您的Django代码更高效,更快速,并使用更少系统资源。 简介 通常,人们首先关心的是编写的代码起作用,其逻辑函数根据需要产生预期输出。然而,有时,这将不足以使代码像我们希望的那样有效地工作。 Generally one’s first concern is to write code that works, whose logic functions as r
我是本地Android开发者,我开始使用Flatter SDK。我开发了一个简单的应用程序,遵循官方的颤振文件。但是我发现调试应用的大小是46MB,对于这个简单的应用来说太大了。有没有办法优化应用程序的大小?因为Flatter应用程序的大小比原生Android应用程序大。